appium上下文切换、webview调试以及chromedriver/键盘等报错问题解决

1、切换上下文

contexts = self.driver.contexts  #获取全部的上下文
self.driver.switch_to.context(contexts[-1])  #切换到webview页面
driver.switch_to.context(contexts[0])   #切换回Native页面

 

2、webview调试

前提条件:

1、手机与电脑连接,手机开启usb调试模式

2、可kexueshangwang

3、打开chrome://inspect/#devices即可,点击inspect可跟web自动化一样定位元素

 

3、切换iframe

这里讲述的是无法通过id、name进行定位的,(若有id、name可直接根据此进行切换),需要通过xpath定位到元素,再进行切换

iframe=self.driver.find_element(*loc)
self.driver.switch_to.frame(iframe)

4、chromedriver报错No Chromedriver found that can automate Chrome '80.0.3987'

下载对应版本的chromedriver,下载地址:http://chromedriver.storage.googleapis.com/index.html

在启动参数加上:

 "chromedriverExecutable":r"D:appiumchromedriverchromedriver.exe"

5、键盘输入账号密码等后,由于没有收起键盘导致无法定位到搜索框或者登录按钮,报错

尝试使用网上的self.driver.hide_keyboard(),但还是不行,于是选择使用keyword,执行:

os.popen("adb shell input keyevent 66")

进行模拟输入法里的搜索按钮,已实验可解决问题


原文地址:https://www.cnblogs.com/nimantou/p/12512514.html