How to click on link element after i element with specific text using watir?

被刻印的时光 ゝ 提交于 2021-01-29 12:29:15

问题


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 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.

Thanks


回答1:


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

Remember when_present method is not necessary because that's automatic. WATIR automatically waits for button/link to exist, present, enabled.



来源:https://stackoverflow.com/questions/61521538/how-to-click-on-link-element-after-i-element-with-specific-text-using-watir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!