首页 > 解决方案 > 无法找到网页元素

问题描述

我找不到 webelement,这个 web 应用程序只能在 Internet Explorer 中打开,我已经使用了所有可能的点击方式,但没有运气。我尝试过的 Xpath 定位器:

"//form[@id='Form1']//a[contains(text(),'Age Range')]"

"//form[@id='Form1']//a[@id='rptTables1_ctl07_hlTablename1']"

我也尝试过使用动作类和javascript点击元素。

附在 URL 中的 DOM,请看这里

标签: seleniuminternet-explorerxpath

解决方案


在节点a中,id值不是静态的,因此您无法使用该id值定位该元素,但您可以使用部分id值,例如,看起来rptTables1_在 id 值中是唯一的,其余部分正在更改,因此应用contains()此值可能有效。

如果只有匹配,请尝试以下 xpath:

//a[contains(@id, 'rptTables1_')]

如果有多个 xpath 匹配项,请通过提供匹配索引来尝试以下 xpath:

(//a[contains(@id, 'rptTables1_')])[Matching index number]

例如,如果匹配索引是,3那么你可以这样写(//a[contains(@id, 'rptTables1_')])[3]

或者,您可以使用Advanced Performance Parameters Panel Topics文本来识别该元素。

//a[contains(text(), 'Advanced Performance Parameters Panel Topics')]

同样,如果有多个匹配项,则尝试使用上述索引方法。

或者您可以尝试以下修改您的 xpaths :

//form[@id='Form1']//a[contains(@id, 'rptTables1_')]

或者

(//form[@id='Form1']//a[contains(@id, 'rptTables1_')])[Matching index number]

或者

//form[@id='Form1']//a[contains(text(), 'Advanced Performance Parameters Panel Topics')]

我希望它有帮助...


推荐阅读