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
990 views
in Technique[技术] by (71.8m points)

selenium - How to identify the xpath for an element that has the same URL appended with page name

I'm trying to find the xpath on a home page that contains menu with multiple items.

<a href="https://test.com/en/" aria-current="page">HOME</a>
<a href="https://test.com/en/blog/">BLOG</a>
<a href="https://test.com/en/resources/">RESOURCES</a>

The language might change when translation test is done. For eg: BLOG

below works for English

a[@href,"https://test.firework.tv/en/"]

But when language changes it fails. Is there a wild card that I can use similar to below?

//a[@href,"https://test.firework.tv/*/"]

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

1 Answer

0 votes
by (71.8m points)
  //a[starts-with(@href, ‘https://test.com/’) and ends-with(@href, ‘blog/’)]

THe above one finds blog

 //a[starts-with(@href, ‘https://test.com/’)]

The above finds all ( its equalent to //a[@href,"https://test.firework.tv//"]

You can use above first syntax all endpoints except home, for home use OR

//a[@href= ‘https://test.com/en/' or @href= ‘https://test.com/lt/']

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

...