Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to double click in Selenium

How to double click in Selenium

We don’t really get to use Double click on these days on web , I mean on web you don’t really need it , but you might want to have a negative test for some buttons or you actually have that functionality on double click a button does something else, so here is how to double click in Selenium.

How to double click in Selenium
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[anyxpath]"))).doubleClick().perform();
Or :
Actions act = new Actions(driver);
 act.moveToElement(driver.findElement(By.xpath("locator"))).doubleClick().build().perform();
How to double click in Capybara:
When /^(?:|I )double[-\s]?click "([^"]*)"$/ do |locator|
  element = page.find(:xpath,"//a[contains(.,'#{locator}')]")
  page.driver.browser.mouse.double_click(element.native)
end
Double click using javascript executor

If from any reasons you can’t use the selenium double click method you can do it using Javascript Executor. For more information you can check the javascript events here.

You should use dblclick event

(JavascriptExecutor) webDriver).executeScript("arguments 
[0].dblclick;", tdElement); 

If you enjoyed this article you can read more from our bunch of articles Test automation tips .

Happy Testing!

jQuery scroll to element

Selenium – What Programming Language You Should Learn

How to Scroll Element into View with Selenium

How to get selenium to wait for ajax response

How to open a new tab with Selenium

How to use Selenium Grid

How to right click using Selenium WebDriver

Ruby Capybara select random value from dropdown

The post How to double click in Selenium appeared first on TestingRepository.



This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

How to double click in Selenium

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×