1.使用 oppo 手機(jī)做自動(dòng)化時(shí)蒲拉,有一個(gè)坑达布,就是webview 頁(yè)面和NATIVE_APP頁(yè)面混搭時(shí)睁冬,你需要先切換NATIVE_APP 上下文募胃,再進(jìn)行webelement元素的定位和處理
2.在使用context切換上下文時(shí)矗晃,你應(yīng)該加上等待時(shí)間仑嗅,以免切換失敗
3."recreateChromeDriverSessions":"true" #切換webview和native時(shí),必須加上此句話张症,才能定位到webview元素 仓技,appium API上說(shuō)的是每次切換到非chrome-Driver時(shí)kill掉session
'''這個(gè)方法是駁回申請(qǐng)'''
def test_bohui(self):
self.driver.switch_to.context('NATIVE_APP')
time.sleep(3)
# 點(diǎn)擊審批按鈕
? ? self.driver.find_element_by_android_uiautomator('new UiSelector().text("審批")').click()
time.sleep(2)
self.driver.switch_to.context('NATIVE_APP')
time.sleep(5)
print('點(diǎn)擊了 我的審批按鈕前')
html =self.driver.page_source
print(html)
print('點(diǎn)擊了 我的審批按鈕前')
context_now ='WEBVIEW_com.flashexpress.backyard'
? ? self.driver.switch_to.context(context_now)
time.sleep(3)
# 點(diǎn)擊我的審批按鈕
? ? wodeshenpi =self.driver.find_element_by_xpath('//*[@id="app"]/div/a[1]')
print(wodeshenpi)
wodeshenpi.click()
time.sleep(2)
self.driver.switch_to.context('NATIVE_APP')
time.sleep(5)
print('點(diǎn)擊了 我的審批按鈕后')
html =self.driver.page_source
print(html)
print('點(diǎn)擊了 我的審批按鈕后')
# 點(diǎn)擊待審批按鈕[996,384][1020,426]? [837,378][963,429]
? ? '''[0,348][1080,822]'''
? ? action2 = TouchAction(self.driver)
action2.press(x=500, y=500).release().perform()
time.sleep(1)
# 頁(yè)面滑動(dòng)一次
? ? l =self.driver.get_window_size()
x1 = l['width'] *0.5? # x坐標(biāo)
? ? y1 = l['height'] *0.75? # 起始y坐標(biāo)
? ? y2 = l['height'] *0.25? # 終點(diǎn)y坐標(biāo)
? ? self.driver.swipe(x1, y1, x1, y2)
time.sleep(1)
self.driver.swipe(x1, y1, x1, y2)
time.sleep(1)
# 點(diǎn)擊駁回按鈕//*[@id="pageTwo"]/div/div[1]/div[6]/span[1]? [60,1602][510,1740]
? ? action2 = TouchAction(self.driver)
action2.press(x=400, y=1700).release().perform()
self.driver.switch_to.context('NATIVE_APP')
time.sleep(5)
html =self.driver.page_source
print('駁回頁(yè)面'*8)
print(html)
print('駁回頁(yè)面' *8)
self.driver.switch_to.context('NATIVE_APP')
time.sleep(5)
eles =self.driver.find_element_by_class_name("android.widget.EditText")
print('bohuide yemian')
print(eles)#返回了3個(gè)元素
? ? print('bohuide yemian')
eles.send_keys("輸入了輸入了輸入了輸入了")
time.sleep(5)
time.sleep(2)
action3 = TouchAction(self.driver)
action3.press(x=700, y=1380).release().perform()
time.sleep(2)