尝试在移动应用中查找元素。
`公共类Ovex { 私有静态AndroidDriver驱动器;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Glaxy S7 edge");
capabilities.setCapability("platformVersion", "8.0.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.ovex_rn");
capabilities.setCapability("appActivity", "com.ovex_rn.MainActivity");
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
driver.findElement(By.xpath("//android.widget.TextView[contains(text(), 'Markets']")).click();
// driver.quit();
} `
这是UI AUtomator Click link to view Xpath from UIAutomator的路径
在此行,调试器显示错误并显示以下错误消息:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
System info: host: 'DESKTOP-45IINVJ', ip: '192.168.210.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.ovex_rn, deviceScreenSize=1440x2560, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=ce051605b4cc832c04, platform=LINUX, deviceUDID=ce051605b4cc832c04, appActivity=com.ovex_rn.MainActivity, desired={appPackage=com.ovex_rn, appActivity=com.ovex_rn.MainActivity, platformVersion=8.0.0, platformName=Android, deviceName=Glaxy S7 edge}, platformVersion=8.0.0, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=SM-G935F, platformName=Android, deviceManufacturer=samsung}]
Session ID: 5b780d61-b329-4a8c-8614-928084365cf8
*** Element info: {Using=xpath, value=//TextView[contains(text(),'Markets')]}
答案 0 :(得分:0)
请将xpath更改为driver.findElement(By.xpath("//android.widget.TextView[@text='Markets']");
,如果要使用contains
,请使用xpath,如下所示:driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Markets')]");
您已经在xpath中使用了text()
,它可用于网络/ mweb自动化,在android应用中,@text
可以代替text()
使用