appium 处理webview
折腾了一段时间,无论是模拟器还是真机,driver.contexts都只有NATIVE_APP,无奈放弃切换webview,直接查找定位元素
from time import sleep
import pytest
from appium import webdriver
class TestWebview:
def setup(self):
caps = {}
caps["platformName"] = "Android"
caps["platformVersion"] = "6.0.1"
caps["deviceName"] = "127.0.0.1:7555" # 60c106df0302
caps["appPackage"] = "io.selendroid.testapp"
caps["appActivity"] = "io.selendroid.testapp.HomeScreenActivity"
caps["autoGrantPermissions"] = True
caps["automationName"] = 'uiautomator2'
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
self.driver.implicitly_wait(20)
def test_webview1(self):
self.driver.find_element_by_id("io.selendroid.testapp:id/buttonStartWebview").click()
sleep(1)
self.driver.find_elements_by_class_name("android.widget.EditText")[0].send_keys("haha")
self.driver.find_elements_by_class_name("android.widget.Button")[1].click()