Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"click and hold" with WebDriver

Is it possible to "click and hold" and element with WebDriver? That is, click an element and not release the click.

like image 662
Randomblue Avatar asked Jan 09 '12 11:01

Randomblue


People also ask

How do you press and hold a key in Selenium?

To hold down a key simultaneously while another key is being pressed, we use the keyDown() and keyUp() methods. Both these methods accept the modifier key as a parameter. The action of these two methods on a key yields a special functionality of a key. All these methods are a part of Actions class in Selenium.

Which code will be used to click and hold through an action method in Selenium?

clickAndHold(webelement).


2 Answers

Actually, for Python Webdriver API (according to tags) it's Action Chains Doc is here

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_xpath(xpath)

def click_and_hold(driver, element):
    ActionChains(driver).click_and_hold(element).perform()
like image 137
Furious Duck Avatar answered Nov 09 '22 05:11

Furious Duck


With WebDriver 'Actions' we can do that:

Actions clkAndHld = new Actions(driver);
clkAndHld.clickAndHold(WebElement).build().perform();
like image 35
Surya Avatar answered Nov 09 '22 03:11

Surya