美文网首页
Appium python 对于oppo手机的webview 页

Appium python 对于oppo手机的webview 页

作者: Leoguo小哥 | 来源:发表于2019-10-09 10:50 被阅读0次

1.使用 oppo 手机做自动化时,有一个坑,就是webview 页面和NATIVE_APP页面混搭时,你需要先切换NATIVE_APP 上下文,再进行webelement元素的定位和处理

2.在使用context切换上下文时,你应该加上等待时间,以免切换失败

3."recreateChromeDriverSessions":"true" #切换webview和native时,必须加上此句话,才能定位到webview元素 ,appium API上说的是每次切换到非chrome-Driver时kill掉session

'''这个方法是驳回申请'''

def test_bohui(self):

self.driver.switch_to.context('NATIVE_APP')

time.sleep(3)

# 点击审批按钮

    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('点击了 我的审批按钮前')

html =self.driver.page_source

print(html)

print('点击了 我的审批按钮前')

context_now ='WEBVIEW_com.flashexpress.backyard'

    self.driver.switch_to.context(context_now)

time.sleep(3)

# 点击我的审批按钮

    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('点击了 我的审批按钮后')

html =self.driver.page_source

print(html)

print('点击了 我的审批按钮后')

# 点击待审批按钮[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)

# 页面滑动一次

    l =self.driver.get_window_size()

x1 = l['width'] *0.5  # x坐标

    y1 = l['height'] *0.75  # 起始y坐标

    y2 = l['height'] *0.25  # 终点y坐标

    self.driver.swipe(x1, y1, x1, y2)

time.sleep(1)

self.driver.swipe(x1, y1, x1, y2)

time.sleep(1)

# 点击驳回按钮//*[@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('驳回页面'*8)

print(html)

print('驳回页面' *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个元素

    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)

相关文章

网友评论

      本文标题:Appium python 对于oppo手机的webview 页

      本文链接:https://www.haomeiwen.com/subject/ezumuctx.html