appium

实践(2)登录功能

2020-05-07  本文已影响0人  落地逃

?unexpected indent

缩进有问题

同理元素定位失败

driver.find_elements_by_xpath('//*[@class="android.widget.EditText"and @index="2"]').send_keys('w.xin_neu@neusoft.com')


from appium1 import driver

from selenium.webdriver.support.ui import WebDriverWait

WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_class_name('android.widget.EditText'))

driver.find_element_by_class_name('android.widget.EditText').send_keys('w.xin_neu@neusoft.com')

WebDriverWait(driver,3).until(lambda,x:x.find_element_by_class_name('android.widget.EditText'))

                                        ^

SyntaxError: invalid syntax

解决:python3.0元素等待方法同2.7不一样,将方法改为

dd=WebDriverWait(driver,3).until(lambda driver:driver.find_element_by_class_name('android.widget.EditText'))

dd.send_keys('w.xin_neu@neusoft.com')


提示No module named 'find_element'

将find_element.appium1 改为appium1 即可


selenium.common.exceptions.WebDriverException: Message: Parameters were incorrect. We wanted {"required":["value"]} and you sent ["text","value","id","sessionId"]

解决:降低selenium 版本

1.查看版本号

2.卸载老selenium

    删除Lib\site-packages下所有selenium开头的文件

3.安装新selenium


####webview元素定位

使用下面语句,执行结果是点击back按钮

driver.find_element_by_xpath('//*[@class="android.widget.Button" and @index="0"]').click()

通过content-desc内容来定位

提示:AttributeError: 'WebDriver' object has no attribute 'find_element_by_accessibility_id'

走了一遍搭建webview环境流程,搞了各种环境都不通,记录下原因

1.使用模拟器-安装chrome版本运行后停止运行

2.真机  需要开发启android webview debug ,我们没有开发人员/或者

3.使用fiddler抓包后在浏览器打开定位

将from selenium import webdriver   换成 from appium  import webdriver  提示cannot  import name webdriver

用的pycharm的方法不适用eclipse 

地址:https://blog.csdn.net/qq_19986309/article/details/79849579

4.用元素坐标方法

APP—H5页面appium元素定位时,鼠标移动到你要定位的元素时显示一团,根本无法定位,网上一堆无用的教程,说什么连接google用inspect定位,超级麻烦,而且不见得有用。

其实用一招就解决这个问题。

先找到你元素的x,y坐标,用一个变量表示,比如tapname

#x,y坐标

tapname = (660,999)

再用os.popen去操作点击坐标的位置

name = os.popen(‘adb shell input tap %s %s’%(tapname[0],tapname[1]))

搞定!!!

就是这么简单。

上一篇 下一篇

猜你喜欢

热点阅读