java - 无法使用相对 xpath 找到元素
问题描述
我目前正在尝试使用 xpath 为我的 selenium 项目定位元素,为什么当我尝试运行 selenium 时,即使它是 DOM 独有的,它也无法使用相对路径定位元素?我的目标是使用 div 标签的 title 属性来定位元素,因为 div 标签是非常动态的。
绝对路径
/html[1]/body[1]/div[2]/div[8]/div[1]/div[3]/div[5]
唯一的相对路径
//*//div[@title='This is the title ']
解决方案
你试过用
//*[@title='This is the title ']
代替
//*//div[@title='This is the title ']
实际上,//*
直接在所有子节点中定位元素。
推荐阅读
- django - 使用 UUID 用户名登录到 Django 管理页面
- python - Julia DataFrames 上的条件选择
- java - 启动应用程序时它崩溃并关闭应用程序
- audio - 如何在archlinux中为每个应用程序选择不同的音频输出
- reactjs - 在 react native 中输入我的 inputText 时如何设置进度条值?
- r - 看似不正确的答案来自 R 中的马赛克Calc::antiD
- pandas - Pandas 从 Dataframe 创建 dict
- javascript - 如果我在 if-else 阶梯中的 if 语句之后没有返回任何内容;默认返回值是多少?
- r - 在 R 中重建数据框的内容
- c# - 我正在将 C# 应用程序从 oracle 11 迁移到 oracle 19,并且正在发生此错误堆栈: