无法点击android.widget.ImageButton

时间:2019-01-30 14:49:06

标签: java eclipse android-emulator appium

我尝试了以下定位器

driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc='Open navigation drawer']")).click();
or
driver.findElement(By.xpath("//android.widget.ImageButton[@index='0'])")).click();
or
driver.findElementByXPath("(//android.view.ViewGroup)[1]").click();

Click on highlighted button

Download = {Link

  

无法单击图像按钮。

@Test
public AndroidDriver<AndroidElement> Loging() throws MalformedURLException, InterruptedException {

    File file = new File("src/test/java", "opentap-v1.1-28012019.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel_C_Edited_API_28");
    capabilities.setCapability(MobileCapabilityType.APP, file.getAbsolutePath());
    AndroidDriver<AndroidElement> driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),
            capabilities);
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.findElement(By.id("com.opentap:id/btn_go")).click();
    driver.findElement(By.id("username")).clear();
    driver.findElement(By.id("username")).sendKeys("kaustubh.patil");
    driver.findElement(By.id("password")).clear();
    driver.findElement(By.id("password")).sendKeys("opentapuat");
    driver.findElement(By.id("rememberMe")).click();
    driver.findElement(By.id("kc-login")).click();
    // driver.findElement(By.id("com.opentap:id/btn_go")).click();
    // Thread.sleep(10000);
    // driver.findElement(By.xpath("//android.widget.ImageButton[@index='0'])")).click();
    // driver.findElementByXPath("(//android.view.ViewGroup)[1]").click();

    // WebDriverWait wait = new WebDriverWait(driver, 25);
    // WebElement element =
    // wait.until(ExpectedConditions.elementToBeClickable(By.id("com.opentap:id/add")));
    /*
     * try { Thread.sleep(1000); WebDriverWait wait = new WebDriverWait(driver, 30);
     * wait.until(driver .findElement(By.
     * xpath("//android.widget.ImageButton[@content-desc='Open navigation drawer']")
     * )); } catch (Throwable error) {
     * Assert.fail("Timeout waiting for Page Load Request to complete."); }
     */
    driver.manage().timeouts().setScriptTimeout(25, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc='Open navigation drawer']")).click();
    return driver;
}

DOM

1 个答案:

答案 0 :(得分:0)

您可以使用触摸动作类和指针来执行您的要求。在以下代码段中使用它会完美地适用于具有绘图仪导航栏的每个应用程序(我已经尝试了许多应用程序,效果很好)。

TouchAction action = new TouchAction(driver);
action.tap (10, 100).perform();

这里,10是X指针,100是Y指针。为什么我给定x为10的原因,绘制图像将位于0-15范围之间,并且您还必须确保绘制位置(对于某些应用程序,它可能位于右侧,因此您必须相应地给出坐标)。