Selenium webdriver Java code using web driver for

2020-02-13 09:56发布

How to write selenium java code for doubleClick() on a record using web driver?

I have displayed some records in the body part. Once I clicked on a record we should get a popup window to update it.

Please suggest how to write Selenium Java code using web driver.

I have tried following code:

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//table/tbody/tr[2]/td/div/div/table/tbody/tr[10]/td[1]"))).doubleClick().build().perform();

8条回答
小情绪 Triste *
2楼-- · 2020-02-13 10:24

Try this code:

Actions action = new Actions(driver);
WebElement btnElement=driver.findElement("Locator of element"));
action.doubleClick(btnElement).build().perform();
查看更多
相关推荐>>
3楼-- · 2020-02-13 10:25
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//table/tbody/tr[2]/td/div/div/table/tbody/tr[10]/td[1]"))).doubleClick().perform();

This code works!!!

查看更多
够拽才男人
4楼-- · 2020-02-13 10:25

And in case if have no additional actions binded to singleclick, you can use:

driver.findElement(By.xpath("%youXPath%"))).click;
driver.findElement(By.xpath("%youXPath%"))).click;

Actually, it should works in most cases (except you have some custom system doubleclick settings)

查看更多
我只想做你的唯一
5楼-- · 2020-02-13 10:28

You should use the Actions() class as this includes a 'double-click' action.

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.linkText("Test"))).doubleClick().build().perform();
查看更多
Animai°情兽
6楼-- · 2020-02-13 10:29

Use Actions class to perform mouse, keyboard actions on WebElements using WebDriver.

Actions action = new Actions(driver);
WebElement element=driver.findElement(By.linkText("TEST"));

//Double click
action.doubleClick(element).perform();

//Mouse over
action.moveToElement(element).perform();

//Right Click
action.contextClick(element).perform();
查看更多
Root(大扎)
7楼-- · 2020-02-13 10:29

I implemented Ran's (immediately above my post) solution. I'm writing Java in Eclipse and using Selenium WebDriver.

There are 2 imports that you'll need:

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

Then, I implemented the code thusly:

WebElement element = driver.findElement(By.xpath("/html/body/div[1]/div/div/div[2]/div[1]/div[3]/div[8]/div[2]/div/div[2]/div/table/tbody/tr[2]"));
Actions builder = new Actions(driver);
builder.doubleClick(element).perform();

Thanks to Ran! I'd been struggling with this one for several hours. Invoking the single click twice doesn't work for me - too much time between the events to be captured by the browser under test as a double-click.

查看更多
登录 后发表回答