How to click on a link with trailing white-space characters on a web page?

江枫思渺然 提交于 2020-03-05 03:22:32

问题


There are links like this on a web page:

  • Overview
  • General Settings
  • AR Server Settings
  • Cache Settings
  • Report Settings
  • Web Service Settings
  • Log Settings
  • Change Password

I am writing an automation script in selenium under Java eclipse and want to click on Cache Settings option. Can some one help? I know this would be simple, but i am a newbie in this world.i am able to automate previous steps til coming to this web page and now stuck in clicking Cache settings.

HTML snippet:

<div class="textMainNav">Cache Settings </div> 
<div class="textMainNav">Report Settings </div>

I have tried few things but none working.


回答1:


To click on the links you can use either of the following solutons:

  • Click on Overview:

    • xpath:

      driver.findElement(By.xpath("//div[@class='textMainNav' and normalize-space()='Overview']")).click();
      


来源:https://stackoverflow.com/questions/53930154/how-to-click-on-a-link-with-trailing-white-space-characters-on-a-web-page

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