0

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
  • Can you paste some of the html, containing the element(s) you're trying to match? Commented May 7, 2013 at 12:47

3 Answers 3

6

Try using the below xpath where we use contains keyword.

//*[contains(@id, 'gritter-item-')]
Sign up to request clarification or add additional context in comments.

1 Comment

I would be very careful with this approach because it can easily match any other ID that has the same format. And assuming this is a auto generated ID I'd say the possibilities that this is true are pretty good.
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-')]

1 Comment

Note that funcions like starts-with and ends-with are XPath 2.0 specific. If you're using Selenium's Firefox WebDriver, for instance, it's not supported.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.