I have seen about 100 touch event examples for the Java webdriver online, but not a single one for python. Would someone be so kind as to post one here, so it saves people many hours of search?Here is my attempt to do a basic double_tap on an element in an android simulator in order to zoom in on it. Much thanks
EDIT: Thanks to Julian's help I was able to figure out the missing link: for some reason, the touch actions require an extra .perform() at the end. Below you will find a bunch of touch events in action--and the code is cleaner. Enjoy!
import unittest, timefrom selenium import webdriverprint "Here are our available touch actions (ignore the ones that look like __xx__): ", dir(webdriver.TouchActions)#print dir(webdriver)class Test(unittest.TestCase): def setUp(self): self.driver = webdriver.Remote(command_executor='http://localhost:8080/wd/hub', desired_capabilities=webdriver.DesiredCapabilities.ANDROID) self.touch =webdriver.TouchActions(self.driver) #self.driver = TouchActions(self.driver) #self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) def testHotmail(self): self.driver.get("http://www.hotmail.com") elem=self.driver.find_element_by_css_selector("input[name='login']") #tap command self.touch.tap(elem).perform() time.sleep(2) elem.send_keys("hello world") time.sleep(2) #double tap self.touch.double_tap(elem).perform() time.sleep(2) #testing that regular webdriver commands still work print self.driver.find_element_by_partial_link_text("Can't access").text elem= self.driver.find_element_by_css_selector("input[type='submit']") self.touch.tap(elem).perform() time.sleep(3) def tearDown(self): time.sleep(3) try: self.driver.quit() except Exception: print(" TearDown Method: Browser seems already closed.") passif __name__ == "__main__": unittest.main()Here is an original Java Example:
WebElement toFlick = driver.findElement(By.id("image"));// 400 pixels left at normal speedAction flick = getBuilder(driver).flick(toFlick, 0, -400, FlickAction.SPEED_NORMAL) .build();flick.perform();WebElement secondImage = driver.findElement(“secondImage”);assertTrue(secondImage.isDisplayed());









