APP WebView

import time
from appium import webdriver

desired_caps = {
                'platformName': 'Android',
                'deviceName': '30d4e606',
                'platformVersion': '7.1.2',
                'appPackage': 'io.appium.android.apis',
                'appActivity': '.ApiDemos',
                'unicodeKeyboard': True,
                'resetKeyboard': True,
                'noReset':True,
          #webview 需要使用的chromedriver
"chromedriverExecutable" : "D:\driverschromedriver.exe" } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 休眠五秒等待页面加载完成 time.sleep(2) print(driver.contexts) driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0))').click() driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("WebView").instance(0))').click() print(driver.contexts) #获取当前页面上下文 contexts=driver.contexts #切进native 进行操作 driver.switch_to.context(contexts[1]) driver.find_element_by_id("i_am_a_textbox").send_keys("hahah") time.sleep(1) # driver.find_element_by_id("i am a link").click() # 切回native driver.switch_to.context(contexts[0]) title = driver.find_element_by_xpath("//android.widget.TextView[@text='Views/WebView']").text print(title)

Appium中混合版app切换带来的问题总结

https://blog.csdn.net/sunfengye/article/details/105564127

chromdriver 下载地址 

https://npm.taobao.org/mirrors/chromedriver/

原文地址:https://www.cnblogs.com/lexus168/p/13941151.html