2016-11-24 75 views
2

我需要一个方法允许长时间点击“密码”空间,因为它在同一行上有一个“眼睛”,但无法找到单独的ID。但我写的程序没有做长时间的点击。请纠正我的代码:在Python中长按

def testDevice1(self): 
    time.sleep(5) 


    username=self.driver.find_element_by_id('com.eas.android:id/front_edit') 
    username.send_keys('[email protected]') 
    time.sleep(5) 
    password = self.driver.find_element_by_id('com.eas.android:id/password') 
    password.send_keys('111111') 
    time.sleep(5) 
    self.driver.longClick('com.eas.android:id/password') 
    time.sleep(10) 
    self.driver.save_screenshot('/home/nat/PycharmProjects/touchoneautomation/appiumTests/screenshots/shot1.png') 
    self.driver.find_element_by_id('com.eas.android:id/btn_login').click() 
    self.driver.save_screenshot('/home/nat/PycharmProjects/touchoneautomation/appiumTests/screenshots/shot1.1.png') 
    time.sleep(5) 
    self.driver.save_screenshot('/home/nat/PycharmProjects/touchoneautomation/appiumTests/screenshots/shot1.2.png') 
    self.driver.find_element_by_id("com.eas.android:id/panel_logout").click() 
    time.sleep(5) 

回答

0

(Python)查找TouchAction。你可以将命令串在一起:

from appium.webdriver.common.touch_action import TouchAction 
ta = TouchAction(driver) 
ta.press(x=x, y=y).release().perform() 

# some_web_obj = driver.find... 
ta.press(some_web_obj).wait(duration_in_millisec).release().perform()