Usage scenario: A Toast pop-up box is common when you manipulate the app, and the Toast bullet information gets to determine whether an operation is successful
Referenced packages: fromselenium.webdriver.support import expected_conditions as Ec,\expected_conditions
From selenium.webdriver.common.by Import by
From Selenium.webdriver.support.ui import webdriverwait
As below, find the toast content below, determine whether the given value is equal to the actual toast value, equality is normal execution, not equal to go directly except exception content, as follows:
The first method of encapsulation:
From selenium.webdriver.common.by import by
from Selenium.webdriver.support.ui import webdriverwait
from Selenium.webdriver.support import expected_conditions as Ec,\
Expected_conditions
def Find_toast2 (self,message): #查找toast值' method explain: Find the value of a toast, just like the Find_toast implementation method, except for the 2 different parameter explain: The toast value of "text" lookup Usage : Device.find_toast2 (' Press again to exit Iber ') 'Logging.info ("Find Toast Value---'%s '"%(message))Try: Message='//*[@text =\ ' {}\ ']'. Format (message) webdriverwait (Self.driver,5,0.5). Until (expected_conditions.presence_of_element_located (by.xpath,message)) Logging.info ("Find toast----%s"%message)returnTrue except: logging.info ("Toast----%s not found"%message)returnFalse
The second method of encapsulation is as follows:
defFind_toast (self,message,timeout=5, poll_frequency =0.5): #查找toast值" method explain: Find the value of the toast parameter explain:" text "Given the toast value Usage:device.find_Toas T (' Press again to exit Iber ') 'Logging.info ("Get Toast Value---'%s '"%message)Try: Toast_loc= ("XPath",".//*[contains (@text, '%s ')]"%message) Webdriverwait (self.driver,timeout,poll_frequency). Until (ec.presence_of_element_located (toast_loc)) Logging.info ("find to toast--'%s '"%message)returnTrue Except:logging.info ("toast--'%s ' not found"%message)returnFalse
Description
Get the Toast method encapsulated click Link: http://www.cnblogs.com/syw20170419/p/8280115.html
Python+appium to find the wrapper for a toast method