【问题标题】:Click on the dynamic element on table which is in the same row that element with known value单击表上与已知值元素位于同一行的动态元素
【发布时间】:2015-06-20 14:34:46
【问题描述】:

我有这样的桌子

<table class="transaction">
<thead class="transaction">
<tr>
<th class="seqtitle" onclick="expandOrCollapse('seq2');">
<a name="seq2"> [Seq: 2]</a>   //dynamic id link
</th>
<th class="transtitle">
 "Some known text + some other dynamic id"  
<span class="toolbar">
  ....

我面临的挑战是当我知道在同一行中有一个元素具有部分已知值时(“一些已知文本 + 一些其他动态 id” )
我尝试使用以下兄弟和前兄弟的 xpath,但没有成功,因为我不知道如何使用 id 访问动态生成的链接
有任何想法吗?

【问题讨论】:

  • 请发布您尝试过的 XPath 并解释该 XPath 有什么问题。

标签: java selenium xpath selenium-webdriver


【解决方案1】:

使用preceding-sibling 轴可以工作,例如:

//table/thead/tr/th[starts-with(., 'Some known text')]/preceding-sibling::th[1]/a

简要说明:

  • th[starts-with(., 'Some known text')] :查找具有以"Some known text" 开头的文本内容的th 元素
  • /preceding-sibling::th[1] :从这样的 th 元素中,找到最近的同级 th 元素
  • /a :从前面提到的每个兄弟th,返回子元素a

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多