简体   繁体   English

如何使用 Selenium Webdriver 双击元素

[英]How to double click on an element using Selenium Webdriver

This is a dynamic list we have in our site.这是我们网站中的动态列表。

列表页

This is the HTML tag where I want to pass double click on.这是我想通过双击的 HTML 标签。

<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我想一直双击第一条记录,即使每次点击后第一条记录都会被删除

Since, you want to double click on the first record, you can try this java code: 既然,你想双击第一条记录,你可以尝试这个java代码:

(Assuming there is one table in the webpage, as complete HTML code is not available above and the row for the contents starts with 2nd.) (假设网页中有一个表,因为上面没有完整的HTML代码,内容的行以2nd开头。)

Actions act = new Actions(driver);
act.doubleClick(driver.findElement(By.xpath("//table//tr[2]//td[@class='dxgv'][1]"))).build().perform();

OR 要么

 Actions act = new Actions(driver);
 act.moveToElement(driver.findElement(By.xpath("//table//tr[2]//td[@class='dxgv'][1]"))).doubleClick().build().perform();

If the double click does not work with the actions class you can use this proposal:如果双击对操作 class 不起作用,您可以使用此建议:

public void doubleClickWithJSExecutor(WebElement element) {
   JavascriptExecutor executor = (JavascriptExecutor) driver;
   executor.executeScript("arguments[0].dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));", element);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM