如何识别表格中的单元格并点击它?

huangapple go评论134阅读模式
英文:

How to identify the cell in the table and click on it?

问题

以下是翻译好的内容:

页面上有一个简单的表格,第一行是列的标题,第二行是动态更改的值。

  1. <div id="...">
  2. <table ...>
  3. <tbody>
  4. <tr> ... <tr>
  5. <tr>
  6. <td class="x11 x22" nowrap>
  7. <a class="xl" href="search"> </a> </td>
  8. <td>...
  9. <td>...
  10. ....

最佳方法是如何识别单元格 - 第一列/第二行以便点击它?
非常感谢!

英文:

There is a simple table on the page, the first raw are the headers of the columns, the second line/raw are the values that are changed dynamically.

  1. &lt;div id = ...&gt;
  2. &lt;table ...&gt;
  3. &lt;tbody&gt;
  4. &lt;tr&gt; ... &lt;tr&gt;
  5. &lt;tr&gt;
  6. &lt;td class=&quot;x11 x22&quot; nowrap&gt;
  7. &lt;a class=&quot;xl&quot; href=&quot;search&quot;&gt; &lt;/a&gt; &lt;/td&gt;
  8. &lt;td&gt;...
  9. &lt;td&gt;...
  10. ....

What is the best way to identify the cell - first column/second line in order to click on it?
Many thanks!

答案1

得分: 1

如果您想点击第一个元素,则XPath将是:

  1. (//a[@href='search'])[1]

对于第二个元素,XPath将是:

  1. (//a[@href='search'])[2]

依此类推...

完整代码应如下:

  1. WebElement element = driver.findElement(By.xpath("(//a[@href='search'])[2]"));
  2. element.click();
英文:

If you want to click on the first element then the xpath would be:

  1. (//a[@href=&#39;search&#39;])[1]

and for second element it would be:

  1. (//a[@href=&#39;search&#39;])[2]

and so on..

Full code should be like:

  1. WebElement element = driver.findElement(By.xpath(&quot;(//a[@href=&#39;search&#39;])[2]&quot;));
  2. element.click();

huangapple
  • 本文由 发表于 2020年4月4日 03:21:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/61019038.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定