Android Appium Chrome按钮不点击或点击?

时间:2017-11-17 08:22:25

标签: java google-chrome selenium appium

我能够点击链接和文字,但我无法使用Chrome和Android Appium点击按钮

public void testcheck() {
    System.out.println("Select");
    //<a id="vivKo" href="javascript:void(0);" class="btn btn- green vivKo at_vivKo">
    //<span class="text">vivKo</span>
  //  <i class="fa fa-chevron-right"></i>  </a>
    //driver.findElementByXPath("//span[contains(., \"" + vivKo + "\")]").click();
    WebElement vova = (WebElement) driver.findElementByXPath("//*[@id=vivKo']");
    TouchAction ta = new TouchAction(driver);
    ta.longPress(vova);
    //WebElement vova = (WebElement) driver.findElementByXPath("//*[@id='vivKo']");
    driver.findElement(By.xpath("//*[@id='vivKo']")).click();
    WebElement elementToClick = driver.findElement(By.xpath("//*[@id='vivKo']"));
    Actions actions = new Actions(driver);
    new WebDriverWait(driver, 60).until(ExpectedConditions.visibilityOf(vova));
    actions.moveToElement(elementToClick).click().build().perform();

错误:FAILED:testcheck

org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (180, 630)
(Session info: chrome=62.0.3202.84)
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 237 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'AMAC02T90QRGTFM', ip: '192.168.14.180', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{deviceScreenSize=1440x2960, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=9887fc35525a485333, platform=LINUX, deviceUDID=9887fc35525a485333, desired={platformVersion=7.0, browserName=Chrome, platformName=Android, deviceName=Vovchik}, platformVersion=7.0, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, browserName=Chrome, javascriptEnabled=true, deviceModel=SM-G950U, platformName=Android, deviceManufacturer=samsung}]
Session ID: 10923751-6fb6-48d1-b61d-50be29f84770
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at 

1 个答案:

答案 0 :(得分:0)

如果你知道有一个元素没有显示在屏幕上但仍然可以通过驱动程序获取,你可以在尝试点击之前向上滑动(例如100像素)。

int x = element.getLocation().getX();
int y = element.getLocation().getY();
new TouchAction(driver)
  .press(x, y)
  .waitAction(ofMillis(500))
  .moveTo(x, y+100)
  .release()
  .perform();

当然,您可以根据帐户的屏幕尺寸计算更准确的px偏移。