【问题标题】:Xpath for Multiple table td element多表 td 元素的 Xpath
【发布时间】:2019-06-21 15:14:41
【问题描述】:

有一个 webtable,我只需要从第一行第二第三和第四列中进行选择。 我尝试使用 AND 运算符选择多个 td 但 xpath 不起作用。

第一行的 Xpath 效果很好

((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]

选择 td 2nd 的 Xpath 效果很好

((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]//td[position()=2]

选择 td 2nd 3rd 和 4th 列的 Xpath。需要帮助不起作用

 ((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]//td[position()=2 and position()=3 and position()=4]

【问题讨论】:

  • 第三次使用 List? (和 getelementS)?

标签: java selenium selenium-webdriver xpath


【解决方案1】:

如果您真的想使用 XPath,请执行以下操作:

  • descendantax 用于遍历table标签定位第一个tr元素
  • position() 函数将行限制为仅“有趣”:

    //table/descendant::tr[1]/td[position() >= 2 and position() <= 4]
    

参考资料:

另外请注意,您可以使用 Html Elements framework 中的 Table class - 它为您提供了一个清晰的 API 来处理表格。

【讨论】:

  • 这不能按需要工作 ((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]//td[position() >= 2 和 position()
  • 如何从 tr 中删除 ((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2] td 1
  • 我为您提供了从表中提取 2 到 4 行的方法,除非我看到 AUT 代码,否则我不知道您的其余查询是否良好。此外,您甚至无法正确复制和粘贴它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-06
  • 1970-01-01
  • 1970-01-01
  • 2010-10-03
  • 1970-01-01
相关资源
最近更新 更多