Ruby on Rails:Xpath:无法检索 XPath

发布于 2024-09-07 18:33:30 字数 1052 浏览 4 评论 0原文

这是我得到的错误:

NativeException: java.lang.RuntimeException: Could not retrieve XPath >//id[@class='open'//@id='status_open']< on HtmlPage(http://cucumber.test.com/proposals/view-me/edit#)@17325460 (Culerity::CulerityException)

这是我的 Cucumber 命令

Then the "li" tag with the id "status_open" should have the class "open"

这是我的步骤定义

Then /^the "([^\"]*)" tag with the id "([^\"]*)" should have the class "([^\"]*)"$/ do |tag,id,clas|


if page.respond_to? :should
      page.should have_xpath("//#{tag}[@class='#{clas}',@id='#{id}']")
    else
      assert page.have_xpath("//#{tag}[@class='#{clas}',@id='#{id}']")
    end
end

,这是 HTML:

<li class="open" id="status_open">
                      <a href="#">
                        Open
                      </a>
                    </li>

基于此教程,它似乎应该可以工作:

http://www.w3schools.com/xpath/xpath_syntax.asp

想法?

This is the error I get:

NativeException: java.lang.RuntimeException: Could not retrieve XPath >//id[@class='open'//@id='status_open']< on HtmlPage(http://cucumber.test.com/proposals/view-me/edit#)@17325460 (Culerity::CulerityException)

This is my Cucumber command

Then the "li" tag with the id "status_open" should have the class "open"

This is my step definition

Then /^the "([^\"]*)" tag with the id "([^\"]*)" should have the class "([^\"]*)"$/ do |tag,id,clas|


if page.respond_to? :should
      page.should have_xpath("//#{tag}[@class='#{clas}',@id='#{id}']")
    else
      assert page.have_xpath("//#{tag}[@class='#{clas}',@id='#{id}']")
    end
end

and here is the HTML:

<li class="open" id="status_open">
                      <a href="#">
                        Open
                      </a>
                    </li>

it seems like it should work, based on this tutoraial:

http://www.w3schools.com/xpath/xpath_syntax.asp

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2024-09-14 18:33:30

//id[@class='open'//@id='status_open']

不是语法上正确的 XPath 表达式。

我必须猜测...也许你想要

//li[@class='open' and @id='status_open']

//id[@class='open'//@id='status_open']

is not a syntactically correct XPath expression.

I have to guess... Maybe you wanted:

//li[@class='open' and @id='status_open']

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文