Python+appium to find the wrapper for a toast method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.