Recently in the study Appium+python write Android automated test scripts, before using Selenium+python to write web-based automated test scripts, on this basis to modify.
Or using a Pom, a page page encapsulates some public methods for a test_case,base. Encapsulates a common method for finding elements:
def find_element (self, *loc):
Try
Webdriverwait (self.driver,10,0.5). Until (ec.visibility_of_element_located (Loc))
Return Self.driver.find_element (*loc)
Except Assertionerror as E:
Self.driver.close ()
*loc indicates that this is a tuple object.
This method is called before using the selenium to write the page to find the element, for example:
Login_username_loc = (By.xpath, ' XXX ')
el = Self.find_element (*self.login_button_loc)
Appium's Webdriver New Find element method, I want to find the element through accessibility_id, find_element_by_accessibility_id method. But there is no accessibility_id in Selenium's selenium.webdriver.common.by, as shown below, only: ID, XPATH, link_text, Partial_link_text, NAME, Tag_name, Class_name, Css_selector.
Class by (object):
"""
Set of supported locator strategies.
"""
id = "ID"
XPath = "XPath"
Link_text = "link TEXT"
Partial_link_text = "Partial LINK TEXT"
Name = "Name"
tag_name = "Tag NAME"
Class_name = "Class NAME"
Css_selector = "CSS SELECTOR"
Looking for Webdriver found in Appium, the new Appium.webdriver.common.mobileby has a Mobileby object, which is an extension of the by object.
So you can use Mobileby to locate objects:
Login_button_loc = (mobileby.accessibility_id, ' login ')
el = Self.find_element (*self.login_button_loc)
This avoids the re-encapsulation of public methods and the ability to locate elements through previous public methods.
Appium Public Method Encapsulation