如何使用Selenium Webdriver双击元素
问题描述:
这是我们网站上的动态列表.
This is a dynamic list we have in our site.
这是我要通过双击的HTML标记.
This is the HTML tag where I want to pass double click on.
<td class="dxgv" align="left" style="color: rgb(51, 51, 51); font-size: 13px; border-bottom: 1px solid rgb(237, 237, 237); border-left-width: 0px; border-right-width: 0px; width: 5.6em; max-width: 6em; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;">Sun Kumar</td>
即使每次单击后都会删除第一条记录,我也要一直双击第一条记录.
I want to double click on the first record all the time even though first record gets deleted after each click
答
由于您要双击第一条记录,因此可以尝试以下Java代码:
Since, you want to double click on the first record, you can try this java code:
(假设网页中有一个表格,因为上面没有完整的HTML代码,内容的行从2nd开始.)
Actions act = new Actions(driver);
act.doubleClick(driver.findElement(By.xpath("//table//tr[2]//td[@class='dxgv'][1]"))).build().perform();
或
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath("//table//tr[2]//td[@class='dxgv'][1]"))).doubleClick().build().perform();