每次加载页面gest后,Xpath都会发生变化 [英] Xpath changing after the page gest loaded every time
问题描述
我正在使用Selenium WebDriver和Java。我正在尝试访问该页面中的登录ID文本框,但每次登录和注销时,登录ID文本框的XPath值都会更改,因此我无法检测到登录ID文本框每次使用相同的代码。
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.
我需要在代码中进行哪些修改才能使用一段代码访问所有动态XPath?
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?
推荐答案
以下是您可能用作解决方法的示例
Below is an example of what you could potentially use as a workaround
xpath类型:
- 多个匹配:
// div [@ class ='class'并包含(text(),'text')]
- 部分匹配:
// span [contains(class,'class')]
- starts-with:
//输入[starts-with(@ name,'input')
- 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.
有关详细信息,请参阅:https://sqa.stackexchange.com/questions/10342/how-to-find-element- using-contains-in-xpath
For more information please see: https://sqa.stackexchange.com/questions/10342/how-to-find-element-using-contains-in-xpath
这篇关于每次加载页面gest后,Xpath都会发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!