如何使用 watir 在具有特定文本的 i 元素之后单击链接元素?
对于这种类型的链接,我很高兴使用
For this type of link I am happily using
@browser.link(:text => "Reports").when_present.click
<a href="/Reports/">Reports</a>
但是我在这个例子中挣扎
However I am struggling with this example
<a href="#">
<i class="no-icon"></i>
Staff
<img src="/Images/Menu/arrow.gif" class="arrow">
</a>
我也想通过文本点击链接,但由于 i 元素没有找到.我不想使用 xpath,所以任何人都可以提出更好的方法.
I am wanting to click the link by text also but it is not found due to i element. I do not want to use xpath so can anyone advise a better way please.
谢谢
下面给出的代码对我来说很好.
The given below code works for me fine.
browser.link(text: "Staff").click
如果它不起作用,也许你可以试试这个
If it's not working, perhaps you may try by this
browser.element(link: "Staff").click
如果还是不行就写下面的代码
If it's still not working then write the following code
browser.element(xpath: "//img[@src='/Images/Menu/arrow.gif']/..").click
记住 when_present
方法不是必需的,因为这是自动的.WATIR 会自动等待按钮/链接存在、存在、启用.
Remember when_present
method is not necessary because that's automatic. WATIR automatically waits for button/link to exist, present, enabled.