Appium新版本遇到的问题,不能通过 name 去定位元素抛 Message: Locator Strategy 'name' is not supported for this session
环境:
1、Appium: 1.15.1
2、Python: 3.7.0
3、Selenium: 3.141.0
4、IDE: Pycharm
5、PC:Windows 10
问题:在 Pycharm 中输入 driver.find_element_by_后可以直接联想出name这个,然后就通过这个name属性去定位界面元素,在运行时居然报 "Locator Strategy 'name' is not supported for this session",从这个错误来看,显然可以看出不是selenium的锅,要不然 pycharm 也不可能联想出来,那么这个很可能是 appium 不支持这个属性了,据说是从appium 1.5版本之后就不支持这个了,为了验证这个观点,到这个目录下:C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\build\lib 找到 driver.js 打开如下,看到没它只支持下面五种属性
class AndroidDriver extends _appiumBaseDriver.BaseDriver {
constructor(opts = {}, shouldValidateCaps = true) {
super(opts, shouldValidateCaps);
this.locatorStrategies = ['xpath', 'id', 'class name', 'accessibility id', '-android uiautomator'];
this.desiredCapConstraints = _desiredCaps.default;
this.sessionChromedrivers = {};
this.jwpProxyActive = false;
this.jwpProxyAvoid = _lodash.default.clone(NO_PROXY);
this.settings = new _appiumBaseDriver.DeviceSettings({
那么如果一定要用name这个属性来进行元素定位的话,那么如何操作呢,下面介绍两种方法:
1、修改driver.js文件,添加name到locatorStrategies里去,经验证这种方法不可行,仍然报同样错误,显然通过简单的修改这个方式不太可行
class AndroidDriver extends _appiumBaseDriver.BaseDriver {
constructor(opts = {}, shouldValidateCaps = true) {
super(opts, shouldValidateCaps);
this.locatorStrategies = ['xpath', 'id', 'class name', 'accessibility id', '-android uiautomator', 'name'];
this.desiredCapConstraints = _desiredCaps.default;
this.sessionChromedrivers = {};
this.jwpProxyActive = false;
this.jwpProxyAvoid = _lodash.default.clone(NO_PROXY);
this.settings = new _appiumBaseDriver.DeviceSettings({
driver.find_element_by_name("Browsing").click()
2、通过find_element_by_android_uiautomator这个来进行元素定位,这个是基于uiautomator原生的来支持,这个肯定是会支持界面中所有支持的元素定位,直接上脚本,这个是可以正常跑通的。
# -*- coding:utf-8 -*- import unittest
import time
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC server = 'http://localhost:4723/wd/hub'
desired_capabilities = {
'platformName': 'Android',
'deviceName': 'abcdefg1234',
'appPackage': 'com.sina.weibo',
'appActivity': 'com.sina.weibo.VisitorMainTabActivity',
'autoGrantPermissions': True
} driver = webdriver.Remote(server, desired_capabilities) time.sleep(30) driver.find_element_by_android_uiautomator("new UiSelector().text(\"Browsing\")").click()
建议:以后在写适用appium自动化框架的脚本时,凡是不能通过这几个属性['xpath', 'id', 'class name', 'accessibility id']直接定位元素的,都直接用 '-android uiautomator' 这个属性来进行定位,其实大家也能发现,前面那几个属性在uiautomator里面是全部包括的(xpath除外),下面把这几个对应关系列举如下:
driver.find_element_by_id("com.sina.weibo:id/tv_title_lookaround").click() <==> driver.find_element_by_android_uiautomator("new UiSelector().resourceId(\"com.sina.weibo:id/tv_title_lookaround\")").click()
driver.find_element_by_name("Browsing").click() <==> driver.find_element_by_android_uiautomator("new UiSelector().text(\"Browsing\")").click()
driver.find_element_by_accessibility_id("Browsing").click() <==> driver.find_element_by_android_uiautomator("new UiSelector().description(\"Browsing\")").click()
driver.find_element_by_class_name("android.widget.TextView").click() <==> driver.find_element_by_android_uiautomator("new UiSelector().className(\"android.widget.TextView\")").click()
注:以上四个对应关系并没有一个一个去验证,只是根据自己的理解写出来,有错误的地方还请各路英雄好汉指出,谢谢!
Appium新版本遇到的问题,不能通过 name 去定位元素抛 Message: Locator Strategy 'name' is not supported for this session的更多相关文章
- Appium问题解决方案(5)- selenium.common.exceptions.InvalidSelectorException: Message: Locator Strategy 'name' is not supported for this session
背景 使用Appium Server 1.15.1版本 执行了以下脚本 test = driver.find_element_by_name("自动化测试") print(test ...
- appium 使用name 定位报错 Locator Strategy 'name' is not supported for this session【appium-desktop】
RF中使用 name定位 报错提示: Locator Strategy 'name' is not supported for this session 解决: 1.打开本地文件 driver.js ...
- appium 使用name 定位报错 Locator Strategy 'name' is not supported for this session
RF中使用 name定位 报错提示: Locator Strategy 'name' is not supported for this session 解决: 1. 打开本地文件 driver.js ...
- appium解决无法通过name属性识别元素org.openqa.selenium.InvalidSelectorException: Locator Strategy 'name' is not supported for this session
执行代码.: public AndroidDriver<AndroidElement> appiumDriver; appiumDriver.findElement(By.name(&qu ...
- Appium 运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for (转)
现象:Appium运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported f ...
- Appium移动端自动化:Appium-Desktp的使用以及定位元素方式总结
一.appium-desktop功能介绍 1.打开appium-desktop,点击start session 2.打开后,点击屏幕右上角的搜索按钮 3.然后会打开配置页面,在本地服务配置信息同上面写 ...
- RobotFramework+Appium 升级Appium v1.10.0后,执行click element时报错:InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for this session,解决办法
报错信息如下: debug] [35m[XCUITest][39m Connection to WDA timed out[debug] [35m[XCUITest][39m Connection t ...
- appium新版本不支持findElementByName,切换到findElementByAndroidUIAutomator
appium 1.7.6 不支持findElementByName(locator) 不知道为什么? 脚本中许多这样的语句,麻烦事情多了 org.openqa.selenium.InvalidSel ...
- Appium新版本不再支持ByName定位了怎么办
appium版本在1.5以后就不再支持ByName的定位,本文章仅介绍在appium1.6.3/1.6.4/1.6.5版本下如何支持ByName定位,适用于安卓.在使用appium1.5之后的版本时, ...
随机推荐
- UESTC-1964命运石之门(类似SPFA的BFS)
命运石之门 Time Limit: 1000 MS Memory Limit: 256 MB Submit Status "这一切都是命运石之门的选择!" 凶真博士发明了能 ...
- Python爬虫技术:爬虫时如何知道是否代理ip伪装成功?
前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. python爬虫时如何知道是否代理ip伪装成功: 有时候我们的爬虫程序添加了 ...
- 查看yum已安装的包
在linux下如何使用yum查看安装了哪些软件包 列出所有已安装的软件包 yum list installed yum针对软件包操作常用命令: 1.使用 yum 查找软件包 命令:yum search ...
- Vue ---- 项目与环境搭建 初始项目结构 Vue生命周期
目录 1. vue环境搭建 2. Vue项目搭建 pycharm配置并启动vue项目 3 . 认识项目 1. vue项目目录结构 2. 配置文件:vue.config.js 3. main.js 4. ...
- XML字符串转为Map集合
public class xmlToMapUtils { /** * xml字符串转为map集合 * @param xmlStr * @return */ public static Map<S ...
- 大白话简单工厂模式 (Simple Factory Pattern)
大白话简单工厂模式 (Simple Factory Pattern) 从买车经历说起 毕业两年,码农张小两口无法忍受挤公交,凌晨起床抢火车票的痛苦,遂计划买车.逛了多家4S店,最终定下日产某车型的轿车 ...
- 微信小程序目录结构与配置介绍
一.小程序结构目录 小程序框架提供了自己的视图层描述语言 WXML 和 WXSS,以及 JavaScript,并在视图层与逻辑层间提供了数据传输和事件系统,让开发者能够专注于数据与逻辑. 官网 1.1 ...
- ASP.NET4.0中JavaScript脚本调用Web Service 方法
环境:VS2019 .net 4.0 framework 根据教材使用ScriptManager在JavaScript中调用Web service 时,失败.现将过程和解决方法记录如下: 1.定义W ...
- ASP.NET MVC项目中EntityFramework"代码优先方法"的使用步骤
EF提供了三种方式来实现项目,分别是: (1)代码优先方法: (2)模型优先方法: (3)数据库优先方法: 本篇主要记录在Vs2010环境下使用代码优先的方式实现数据库和后端代码数据交互,语言为C#, ...
- C# List集合 GroupBy分组
var grpBalance = listBalance.GroupBy(m => new { m.MerChantId, m.Name}).Distinct().Select(t => ...