ruby-on-rails - Watir 返回不正确的子表
问题描述
我有两个具有相同属性 ( random-attribute
) 的表,这是识别它们的最独特方式。区分它们的唯一方法是通过它们所属的父 div(参见下面的示例)。
<div class="header">
<table random-attribute="left-desc">
</table>
<table random-attribute="main-desc">
</table>
<div>
<div class="body">
<table random-attribute="left-desc">
</table>
<table random-attribute="main-desc">
</table>
<div>
我正在尝试获取main-desc
属于 的表的内容,<div class="body">
但下面的代码不断返回我的表内容<div class="header">
browser = Watir::Browser.new
browser.goto(MY_URL_PAGE)
browser.div(class: "body").table(xpath: '//table[@random-attribute="main-desc"]')
奇怪的部分是,如果我运行browser.div(class: "body")
它会返回正确表的内容,但是当我链接它时,browser.div(class: "body").table(xpath: '//table[@random-attribute="main-desc"]')
它会返回表browser.div(class: "header")
解决方案
记住包含 XPath 的初始点是 Watir 试图避免使用 XPath 的原因之一。要避免 XPath,您可以执行以下操作:
browser.div(class: "body").table(random_attribute: "main-desc")
推荐阅读
- keras - 从 YOLOv3 获取特征提取
- python-3.x - 命令引发异常:HTTPException:400 Bad Request(错误代码:50007):无法向该用户发送消息
- sql-server - EF Core 3.1 产生不正确的查询翻译
- c# - SQL命令中Try-Catch的不一致问题,用C#执行
- batch-file - 任何程序退出后如何在DOS中执行文件?
- git - 如果不使用 --dir-diff 选项,为什么 git difftool 不会在 macOS 上开始融合?
- java - 空气阻力在这个模拟中导致速度急剧上升
- visual-studio-2019 - -d.lib 和普通的 SFML-system.lib 有什么不同?
- javascript - 如何使用 javascript 在现有选项卡中添加 thead 和 tbody 标签
- arrays - 如何在菜单驱动的 C 程序中增加和减少 char 指针?