如何选择表格中的行并选择旁边的特定单选按钮(How to select a row in a table and select a specific radio button next to it)

编程入门 行业动态 更新时间:2024-10-19 18:18:40
如何选择表格中的行并选择旁边的特定单选按钮(How to select a row in a table and select a specific radio button next to it)

我想在网站的表格中选择一个特定的行,然后选择它旁边的按钮。 我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();

更多推荐

本文发布于:2023-08-04 10:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何选择   单选   表格   按钮   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!