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

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

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

问题

以下是翻译好的内容:

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

<div id="...">
  <table ...>
    <tbody>
      <tr> ... <tr>
        <tr>
          <td class="x11 x22" nowrap>
            <a class="xl" href="search"> </a> </td>
          <td>...
          <td>...
    ....

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

英文:

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.

&lt;div id = ...&gt;
  &lt;table ...&gt;
    &lt;tbody&gt;
      &lt;tr&gt; ... &lt;tr&gt;
        &lt;tr&gt;
          &lt;td class=&quot;x11 x22&quot; nowrap&gt;
             &lt;a class=&quot;xl&quot; href=&quot;search&quot;&gt; &lt;/a&gt; &lt;/td&gt;
          &lt;td&gt;...
          &lt;td&gt;...
      ....    

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

答案1

得分: 1

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

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

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

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

依此类推...

完整代码应如下:

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

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

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

and for second element it would be:

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

and so on..

Full code should be like:

WebElement element = driver.findElement(By.xpath(&quot;(//a[@href=&#39;search&#39;])[2]&quot;));
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:

确定