Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 2.0 WebDriver Advcanced Interactions DoubleClick Help (c#)

So within my selenium regression tests, I've been trying to double click on a calendar to make a new appt. I have attempted to use the doubleClick(); method within the advanceduserinteractions library, but there is an issue; the two clicks aren't fast enough/close enough together to fire an actual double-click! Has anybody found a way to deal with this in their testing?

like image 312
spacebed Avatar asked Dec 05 '11 15:12

spacebed


People also ask

How do you right click on an action class?

Actions class is a predefined class in Selenium web driver used to perform multiple keyboard and mouse operations such as Right Click, Drag and Drop, etc. Actions actions = new Actions(driver); WebElement elementLocator = driver. findElement(By.id("ID")); actions. doubleClick(elementLocator).


5 Answers

This code works for me!

Actions action = new Actions(driver);
action.doubleClick(myElemment);
action.perform();
like image 121
Verica Avatar answered Nov 02 '22 06:11

Verica


Here is the Java equivalent. This code will blindly open the first event. You could add some logic to open a specific event etc. This code works! (tested with 2.12)

List<WebElement> events = driver.findElements(By.cssSelector("div.dv-appointment"));
for(WebElement event:events){
    WebElement body = event.findElement(By.cssSelector("div.body"));            
    if(!body.getText().isEmpty()) //or open a known event
    {
        System.out.println(body.getText()); //open the first event
        Actions builder = new Actions(driver);
        Action doubleClick = builder.doubleClick(event)
                                    .build();
        doubleClick.perform();
        break;                  
    }
}
like image 30
nilesh Avatar answered Nov 02 '22 06:11

nilesh


Do not forget "using"

using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Support.UI;

//create Actions object
Actions builder = new Actions(driver);
//create a chain of actions 
builder.DoubleClick().Build().Perform();

http://selenium-interview-questions.blogspot.ru/2014/03/how-to-double-click-on-web-element.html

like image 29
Mikhail Avatar answered Nov 02 '22 08:11

Mikhail


I too had the problem where Selenium's doubleclick event works in Firefox but has no effect in Chrome. Upgrading to Selenium didn't help; I already have the latest version. (My environment is Ubuntu 14.04, Python 2.7.6, Selenium 2.44.0, Firefox 35.0, Chrome 40.0.2214.91.)

I'm not sure why CBRRacer's answer was downvoted. I successfully worked around the problem by using two click events. This works in both Firefox and Chrome. There are two ways do to it, and both worked for me.

The first way:

elem = driver.find_element_by_css_selector('#myElement')
elem.click()
elem.click()

The second way:

elem = driver.find_element_by_css_selector('#myElement')
actions = webdriver.ActionChains(driver)
actions.click(elem).click(elem).perform()
like image 41
Steve Saporta Avatar answered Nov 02 '22 08:11

Steve Saporta


I quite like the approach used here, particularly queuing the actions first, then performing, since that allows repeated application of the actionchain.

http://selenium-python.readthedocs.org/en/latest/api.html#selenium.webdriver.common.action_chains.ActionChains

From the documentation example linked:

menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")

actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
like image 28
Chris McGinlay Avatar answered Nov 02 '22 07:11

Chris McGinlay