Regular expression for xpath in selenium java code

我的梦境 提交于 2019-12-23 05:27:33

问题


Selenium java code for regular expression.

Xpath = "//*[@id='gritter-item-6']/div[2]/div[2]/p"

In above xpath 6 is varying, any one help me how to solve this problem

Please give me the solution for this.


回答1:


Try using the below xpath where we use contains keyword.

//*[contains(@id, 'gritter-item-')]



回答2:


To make it more accurate, you can use starts-with() instead of contains(), since your IDs are starting with specific string.

You can use : //*[starts-with(@id, 'gritter-item-')]




回答3:


I had the same problem as you, what helped me was to install Selenium IDE and extract the "Xpath Position" the position is not dynamic as long as the button does not change the position on the page. Hope that this helps you.Screenshot



来源:https://stackoverflow.com/questions/16293632/regular-expression-for-xpath-in-selenium-java-code

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