selenium - 无法找到网页元素
问题描述
我找不到 webelement,这个 web 应用程序只能在 Internet Explorer 中打开,我已经使用了所有可能的点击方式,但没有运气。我尝试过的 Xpath 定位器:
"//form[@id='Form1']//a[contains(text(),'Age Range')]"
和
"//form[@id='Form1']//a[@id='rptTables1_ctl07_hlTablename1']"
我也尝试过使用动作类和javascript点击元素。
附在 URL 中的 DOM,请看这里
解决方案
在节点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')]
我希望它有帮助...
推荐阅读
- php - 样式化我的模态,我需要我的模态有一个红色的背景色
- r - 对数表
- python - 如何使用 python O365 库列出 One Drive 文件夹中的项目
- python-3.x - 启动器中的致命错误:检查 pip 版本时
- azure-aks - 卷“azurefileshare”的 MountVolume.SetUp 失败:无法获取密钥默认值
- swift - UIButton 类中未调用委托方法
- flutter2.0 - flutter2.0 无法安装“xx”
- powershell - 如果我们传递了多个值,如何复制多个值
- python - 使用给定的 bin 大小对给定数组进行随机分区
- debugging - 调试器 Spyder 卡在 SciPy SLSQP 中