我想在网站的表格中选择一个特定的行,然后选择它旁边的按钮。 我xpath=(//a[@id='DeleteLnkBtn'])[4]的问题是每次我选择按钮它会记住位置xpath=(//a[@id='DeleteLnkBtn'])[4]的最后一个按钮但是我想按名称选择行并选择按钮那一行是独一无二的。 有多个具有相同按钮的行都具有相同的名称(删除)。
HTML :
<td>Auto Missed Session 2</td> <a id="DeleteLnkBtn" >Delete</a>我的目的是通过表格“Auto Missed Session 2”中的文本引用该行,然后单击删除按钮。
这是我到目前为止所尝试的。
选项1 - driver.findElement(By.xpath("//tr/td[contains(text() = 'Auto Missed ssion 2', + 'DeleteLnkBtn')]")).click();
选项2 - driver.findElement(By.xpath("(//tr/td[contains(text(),'Auto Missed Session 2' + 'Delete')])")).click();
以上失败说明这不是选项1上的有效Xpath表达而且没有这样的元素:无法在选项2上找到元素
表数据如下所示td> Auto Missed Session 2 / td> - 这是我想要选择的表中行的名称。
a id= "DeleteLnkBtn"这是我想要选择的按钮。
按钮的Xpath是//*[@id="DeleteLnkBtn"]
谢谢。
I would like to select a specific row in a table on a website and select a button next to it. The problem I have is each time I select the button it remembers the last button by position xpath=(//a[@id='DeleteLnkBtn'])[4] but i would like to select the row by name and select the button unique to that row. There are multiple rows with the same buttons all having the same name (Delete).
HTML:
<td>Auto Missed Session 2</td> <a id="DeleteLnkBtn" >Delete</a>My aim is to reference the row by a text in the table "Auto Missed Session 2" and click on the delete button.
Here is what I've tried so far.
Option 1 - driver.findElement(By.xpath("//tr/td[contains(text() = 'Auto Missed ssion 2', + 'DeleteLnkBtn')]")).click();
Option 2 - driver.findElement(By.xpath("(//tr/td[contains(text(),'Auto Missed Session 2' + 'Delete')])")).click();
The above fails stating this is not a valid Xpath expresssion on Option 1 and No such element: unable to locate element on Option 2
The table data looks like this td> Auto Missed Session 2 /td> - This is the name of the row in the table i would like to select.
a id= "DeleteLnkBtn" This is the button i would like to select.
Xpath of the button is //*[@id="DeleteLnkBtn"]
Thanks.
最满意答案
尝试下面的代码,让我知道结果:
driver.findElement(By.xpath("//td[text() = 'Auto Missed Session 2']/following::a[text()='Delete']")).click();Try below code and let me know the result:
driver.findElement(By.xpath("//td[text() = 'Auto Missed Session 2']/following::a[text()='Delete']")).click();更多推荐
发布评论