Regular expression for xpath in selenium java code

2019-06-14 12:31发布

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.

3条回答
ら.Afraid
2楼-- · 2019-06-14 12:40

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

查看更多
Fickle 薄情
3楼-- · 2019-06-14 12:50

Try using the below xpath where we use contains keyword.

//*[contains(@id, 'gritter-item-')]
查看更多
\"骚年 ilove
4楼-- · 2019-06-14 12:52

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-')]

查看更多
登录 后发表回答