英文:
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.
<div id = ...>
<table ...>
<tbody>
<tr> ... <tr>
<tr>
<td class="x11 x22" nowrap>
<a class="xl" href="search"> </a> </td>
<td>...
<td>...
....
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='search'])[1]
and for second element it would be:
(//a[@href='search'])[2]
and so on..
Full code should be like:
WebElement element = driver.findElement(By.xpath("(//a[@href='search'])[2]"));
element.click();
专注分享java语言的经验与见解,让所有开发者获益!
评论