Ben
Ben

Reputation: 31

Selenium 2/Webdriver - how to double click a table row (which opens a new window)

I am using C# with Selenium 2.0 / Webdriver and I'm trying to simulate a double click on a table row that opens a new browser window.

I have two problems:

  1. After locating the table row which has a unique classname (i.e. using findelement(By.classname("..."))) applying the click method (or select/submit) does not perform any action and complains about not being able to perform that kind action on the element in question.

  2. How do you perform a double click in Selenium 2.0/Webdriver ?

Upvotes: 3

Views: 15479

Answers (2)

Ajay
Ajay

Reputation: 4474

For double click you can perform following:

from selenium.webdriver import ActionChains

action_chains = ActionChains(driver)
action_chians.double_click(on_element).perform()

*where, on_element = element on which you want to double click*

I did this using python. and it worked :)

Upvotes: 5

Sergii Pozharov
Sergii Pozharov

Reputation: 17828

  1. You should click on the table cell (<td>) element

  2. Double click is not yet implemented in WebDriver. See Issue #244 for the status. Also the comments to this issue contains a JavaScript that can be used to to the double click in Firefox.

For IE you will need to execute the following:

(IJavaScriptExecutor)driver).executeScript("arguments[0].fireEvent('ondblclick');", cell);

For the Firefox and Chrome:

(IJavaScriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');" +
        "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" +
        "arguments[0].dispatchEvent(evt);", cell);

where the cell is the web element on which you would like to execute the script.

Upvotes: 8

Related Questions