Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

java - Xpath changing after the page gest loaded every time

I am using Selenium WebDriver along with Java. I am trying to access the 'Login ID' text box in that page but every time I am Logging in and out, the XPath value against the 'Login ID' text box changes so I am unable to detect the 'Login ID' text box every time with the same code.

What modifications do I need to make in my code so that I am able to access all the dynamic XPaths with a single piece of code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Below is an example of what you could potentially use as a workaround

Type of xpaths:

  • multiple matches: //div[@class='class' and contains(text(), 'text')]
  • partial match: //span[contains(class, 'class')]
  • starts-with: //input[starts-with(@name,'input')

These are more beneficial when handling dynamic elements and will be robust.

For more information please see: https://sqa.stackexchange.com/questions/10342/how-to-find-element-using-contains-in-xpath


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...