[Mac + Appium + Python3.6 learning (d)] of common IOS automated test automation API summary Selenium2 + python presence Appium + Python3 + iOS judge element positioned element 36-

surroundings:

  • Epochs: 1.9.1
  • Appium-desktop: 1.7.1
  • Xcode:10.0
  • IOS:iPhone5S(10.3.3)
  • Mac:10.13.6

 

① get phone screen size: length, width

" Appium  Appium version 1.9 BUG: Use get_window_size () method error "

Solution:

Copy the code
# 修改路径
......\...python3.6.1-path\Lib\site-packages\selenium\webdriver\remote\remote_connection.py

# 300行
# 原代码
Command.W3C_GET_WINDOW_SIZE:
                ('GET', '/session/$sessionId/window/size'),

# 替换为
Command.W3C_GET_WINDOW_SIZE:
               ('GET','/session/$sessionId/window/$windowHandle/size'),
Copy the code

After the size error to solve:

Copy the code
# Get the phone screen length and width 
self.size self.d.get_window_size = () 

# Get the width of the half 
self.half_Width self.size = [ 'width'] / 2 

# acquires half the length 
self.half_Width = self.size [ 'height ']/2
Copy the code

② sliding method:

Reference: " Appium  Jijiji: Appium1.5.3 there is no method for the new iOS screen slide, swipe coordinate slide is no longer supported, seeking new solutions Python language ."

Copy the code
    def do_swipe(self,x1,y1,x2,y2):
        '''
        # 滑动方法
        :return:
        '''
        self.d.execute_script("mobile: dragFromToForDuration",
                              {"fromX": x1, "fromY": y1, "toX": x2, "toY": y2, "duration": 0.5})
Copy the code

 ②-1: up, down, left, right, scroll method:

driver.execute_script('mobile:scroll', {'direction': '参数'}) # 参数:down,up,right,left

②-2: Also, if you want to simulate the sliding track, such as gesture unlock, it can be (to make it: TouchAction )

Copy the code
# For reference, but not for Python 
Final TouchAction Gesture = new new TouchAction (Driver) .press (startX, stratY) 
     .moveTo (startX, stratY + height) 
     .moveTo (startX, stratY + height + height) 
     .moveTo (startX width +, stratY + height + height) .release (); 
 gesture.perform ();
Copy the code

Positioning a plurality of identical elements ③:

 

Open Address: HTTP: // localhost: 8100 / Inspector

As shown here, will locate the same information multiple elements, if not the appium-desktop positioning elements, we take this way to obtain property to target.

Since the element attributes found, and how to write code that locate it? as follows:

Copy the code
# 点击第一个相同元素
self.d.find_elements_by_name("home arrow news")[0].click()

# 点击第二个相同元素
self.d.find_elements_by_name("home arrow news")[1].click()

# 点击第三个相同元素
self.d.find_elements_by_name("home arrow news")[2].click()
Copy the code

只需要加上【index】角标即可。

④隐藏弹出的输入法,因为怎么试都不行,后来采取的定位背景元素,点击背景,这样就可以间接关闭输入法。

⑤判断可不可以点击元素:

参考:《Selenium2+python自动化36-判断元素存在

Copy the code
    def isExist(self,i):
        '''
        # 判断可不可以点击元素
        :param i:
        :return:
        '''
        try:
            print("已选择:[%s]" % i)
            self.d.find_element_by_name(i).click()
            return True
        except:
            return False
Copy the code

⑤-1判断元素存不存在:

exist = self.d.find_element_by_name(i).is_enabled()
print(exist)
# True/False

⑥常用定位元素方法:

Copy the code
# class_name定位
self.d.find_element(By.CLASS_NAME,"XCUIElementTypeTextField")

# accessibility_id定位
self.d.find_element_by_accessibility_id("login_bg_top")

# name定位
self.d.find_element_by_name("home btn newtask")

# xpath定位
self.d.find_element_by_xpath('//XCUIElementTypeStaticText[@name="xxx"]')

# 还有其他的等等定位详情参考附录的文章
Copy the code

⑦点击元素

self.d.find_element_by_name("home btn newtask").click()

⑧输入值

self.d.find_element_by_accessibility_id("请输入内容").send_keys("xxx")

⑨断言

# 获取元素的值进行断言
text = self.d.find_element_by_accessibility_id("xxx").text
print(text)
self.assertEqual(text,"xxx","显示不对!")

 

附录:

其他appium-IOS自动化API写法参考如下:

" Appium  Appium Chinese version of the Python API-HZJ By "

" Python + Appium + IOS automated testing ."

" Appium + A Python 3 + iOS positioned elements "

" Epochs --- appium常见API "

" Github: appium ask questions address "

" Appium principal elements positioned doubts difficulty "

 Transfer: https://www.cnblogs.com/Owen-ET/p/9967907.html

Guess you like

Origin www.cnblogs.com/dreamhighqiu/p/10989984.html