Appium的此会话问题不支持定位器策略"css选择器" [英] Locator Strategy 'css selector' is not supported for this session issue with appium
问题描述
由于我是移动自动化的新手,所以我一直在尝试使用appium maven和eclipse运行简单的活动.但是,当我尝试运行计算器"应用程序时,打开但元素不可访问.
Since I'm new to mobile automation, I've been trying to run simple activities using appium maven and eclipse. But When I try to run Calculator app opens but the elements are not accessible.
这是我用来运行简单计算器的代码
This the code I used to run a simple calculator
@BeforeClass
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "4.4.2");
capabilities.setCapability("deviceName", "Emulator");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
}
@Test
public void testCal() throws Exception {
WebElement two = driver.findElement(By.name("2"));
two.click();
}
@AfterClass
public void teardown() {
}
我正在使用最新的稳定依赖项. io.appium java-client 7.0.0和 org.testng testng 6.14.3
I am using the latest stable dependencies. io.appium java-client 7.0.0 and org.testng testng 6.14.3
FAILED: testCal
org.openqa.selenium.InvalidSelectorException: Locator Strategy 'css
selector' is not supported for this session
For documentation on this error, please visit:
https://www.seleniumhq.org/exceptions/invalid_selector_exception.html
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {BROWSER_NAME: Android, VERSION: 4.4.2, appActivity:
com.android.calculator2.Cal..., appPackage: com.android.calculator2,
databaseEnabled: false, desired: {BROWSER_NAME: Android, VERSION: 4.4.2,
appActivity: com.android.calculator2.Cal..., appPackage:
com.android.calculator2, deviceName: Emulator, platformName: android},
deviceManufacturer: HUAWEI, deviceModel: FLA-LX2, deviceName:
HXT7N18521000819, deviceScreenSize: 1080x2160, deviceUDID:
HXT7N18521000819, javascriptEnabled: true, locationContextEnabled: false,
networkConnectionEnabled: true, platform: LINUX, platformName: LINUX,
platformVersion: 8.0.0, takesScreenshot: true, warnings: {},
webStorageEnabled: false}
Session ID: a604a166-3c0d-4e9c-a3e4-9b1ea734bee6
*** Element info: {Using=name, value=2}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at...
推荐答案
Appium不是Selenium:它们都是使用JSON Wire协议实现的,并且具有相似的API,但不是相同的API:
Appium is not Selenium: they both implemented using JSON wire protocol and has similar APIs, but not the same ones:
本机android应用程序支持的定位器策略:
Supported locator strategies for Native android app:
- id(资源ID的View属性);
- accessibilityId(内容描述视图属性);
- uiAutomator(最好阅读 UiSelector );
- className(UI组件类型);
- XPath.
- id (resource-id View attribute);
- accessbilityId (content-desc View attribute);
- uiAutomator (better to read about UiSelector);
- className (ui component type);
- XPath.
因此您不能在Android驱动程序会话中使用By.name
定位器策略,这不受支持.
So you cannot use By.name
locator strategy for Android driver session, it's not supported.
为简便起见,我建议在Appium本机测试中使用MobileBy
代替By
:您将获得适当的选项.
To make it easy, I suggest using MobileBy
in place of By
in Appium native tests: you will get the proper options.
这篇关于Appium的此会话问题不支持定位器策略"css选择器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!