Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望单击一个链接,该链接位于第一个表行中,其中包含一些文本。
我尝试了以下
within(all('tr').select {|elt| elt.text == "desired text" }.first) do all('a').first.click end
不幸的是,它不满足真实条件,并且代码从未执行过。我可能需要一个“喜欢”命令或部分文本搜索。
我该怎么做呢?
您可以为您的链接提供一个独特的 CSS 类,例如“foobar”,然后使用以下命令直接单击它:
page.find(:css, ".foobar").click
或尝试使用文本“foobar”搜索行,然后单击该行中包含文本“所需文本”的链接:
page.find(:xpath, "//tr[contains(.,'foobar')]/td/a", :text => 'desired text').click