#coding:utf-8
from appium import webdriver
import time
u\'\'\'智行火车票,webview页面定位\'\'\'
desired_caps = {\'platformName\': \'Android\',
\'deviceName\': \'9a762346\',
\'platformVersion\': \'6.0.1\',
\'noReset\': True,
\'appPackage\': \'com.yipiao\',
\'appActivity\': \'com.zt.main.entrance.ZTLaunchActivity\'}
driver = webdriver.Remote(\'http://127.0.0.1:4723/wd/hub\', desired_caps)
time.sleep(10)
print(driver.context)
driver.find_element_by_xpath(\'//*[@text="我的"]\').click()
time.sleep(3)
driver.find_element_by_xpath(\'//*[@text="产品意见"]\').click()
time.sleep(3)
print(driver.contexts)
driver._switch_to.context(\'WEBVIEW_com.yipiao\')
print(\'切换成功\')
p=driver.page_source
with open(\'1111.html\',\'wb\') as f:
f.write(p.encode(\'utf-8\'))
time.sleep(2)
#driver.find_element_by_xpath("//*[contains(text(),\'【抢票】我能抢到票吗\')]").click()
driver.find_element_by_xpath(".//*[@id=\'container\']/div/div/section[2]/ul/li[2]/a/div[1]/span").click()
处理方法2:
主要是你已经确定他是一个webview,但是打印全部上下文返回的list里只有NATIVE_APP,无法进行切换。
就不要去切换了,当做是APP原生的,只需要定位到某个元素就行
这种情况不建议用获取源码,没太大用。
#coding:utf-8
from appium import webdriver
import time
u\'\'\'百度阅读,webview页面定位\'\'\'
desired_caps = {"platformName": "Android",
"deviceName": "9a762346",
"platformVersion": "6.0.1",
"noReset": True,
"appPackage": "com.baidu.yuedu",
"appActivity": "com.baidu.yuedu.splash.SplashActivity"}
driver = webdriver.Remote(\'http://127.0.0.1:4723/wd/hub\', desired_caps)
time.sleep(10)
driver.find_element_by_accessibility_id(\'VIP\').click()
time.sleep(3)
driver.find_element_by_accessibility_id("规则详情").click()