当前位置: 首页 > 知识库问答 >
问题:

控制台错误“使用给定的搜索参数在页面上找不到元素。”在阿皮姆

冉丰茂
2023-03-14

正在尝试在移动应用程序中定位元素。

'公共类Ovex{私有静态Android驱动程序;

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点击链接查看Xpath从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')]}

共有1个答案

欧阳楚
2023-03-14

请将xpath更改为driver.findElement(By.xpath("//android.widget.TextView[@text='Markets']");,如果您想使用包含,请像这样使用xpath:<--元素(By.xpath("//android.widget.TextView[包含(@text,'Markets')]");

您在用于web/mweb自动化的xpath中使用了text(),在android应用程序中,@text代替了text()

 类似资料: