NoSuchElementException-使用给定的搜索参数无法在页面上找到元素

时间:2020-07-01 15:12:49

标签: android selenium automation

我正在尝试自动化android应用的VideoPlayer,但是当元素显示在NoSuchElementException中时,我遇到了UIAutomator的错误,下面提到了错误:

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

我正在尝试实现自动化的代码如下:

 public static void main(String args[]) throws MalformedURLException, InterruptedException {
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability("automationName", "UiAutomator2");
    dc.setCapability("platformName", "Android");
    dc.setCapability("deviceName", "XXXX");
    dc.setCapability("udid", "XXXXX");
    dc.setCapability("autoAcceptAlerts", "true");
    dc.setCapability("appPackage", "com.xxxxxx");
    dc.setCapability("appActivity", "com.xxxxxx.xxxxxx.xxxxx.activities.MainActivity");

    URL url = new URL("https://xxxxxx/wd/hub");

    try {
        AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(url, dc);
        // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Thread.sleep(4000);
        // Launch The app
        driver.findElementByAccessibilityId("RESULTS").click();
        Thread.sleep(4000);
        driver.findElementByAccessibilityId("FEATURED").click();
        Thread.sleep(4000);
        driver.findElementByAccessibilityId("VIDEOS").click();
        Thread.sleep(4000);
        driver.findElementByXPath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/androidx.drawerlayout.widget.DrawerLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.FrameLayout/android.widget.ImageView[2]")
                .click();
        
        Thread.sleep(7000);
      
    driver.findElementByAccessibilityId("Video Player").click();

下面,我还将分享UIAutomator的屏幕截图。

enter image description here

如果有人知道如何解决此问题,请告诉我。仅供参考,我也尝试过findElementByIdfindElementByXPath

0 个答案:

没有答案