在模拟器/真实设备上滚动后无法单击元素

时间:2019-09-03 14:33:43

标签: java ios selenium appium appium-ios

滚动后,我尝试查找并单击一个元素,但java未能执行此操作,并显示“无此类元素异常”错误,这很奇怪,因为如果我尝试单击xpath就是正确的,并且该元素在那里,在滑动之前会找到该元素,但只有在滑动然后向后滑动该元素所在的位置之后,我才会遇到该异常,我要确保该元素在手机屏幕上可见。

我想我已经尝试了所有组合,例如driver.getpagesource(),锁定和解锁设备,runappinthebackground,但无法单击该元素。

  //the element is here but i have to do some other operations before and those operations take me to the end of the screen, thats why i have to swipe back with following code to get back to where my element is located.




int startX = licenceLabel.getLocation().getX() + (licenceLabel.getSize().getWidth() / 2);
            int startY = licenceLabel.getLocation().getY() + (licenceLabel.getSize().getHeight() / 2);

            int endX = paintLabel.getLocation().getX() + (paintLabel.getSize().getWidth() / 2);
            int endY = paintLabel.getLocation().getY() + (paintLabel.getSize().getHeight() / 2);

            TouchAction action = new TouchAction(driver);
            action.longPress(PointOption.point(startX, startY))
                    .moveTo(PointOption.point(endX, endY))
                    .release()
                    .perform();

            System.out.println("swipe complete");

            Thread.sleep(3000);
            MobileElement el1 =  driver.findElementByXPath("//XCUIElementTypeOther[@name='Federal Motor Vehicle Standards Compliance Label']/XCUIElementTypeButton[1]");
            el1.click();

    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: https://www.seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'spro', ip: 'fe8...', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '1.8.0_162'
    Driver info: io.appium.java_client.ios.IOSDriver
    Capabilities {app: ..., autoAcceptAlerts: true, autoWebview: false, automationName: XCuiTest, browserName: , databaseEnabled: false, deviceName: iPhone 8, fullReset: false, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, noReset: true, platform: MAC, platformName: iOS, platformVersion: 12.2, takesScreenshot: true, udid: 6CD3..., webStorageEnabled: false}
    Session ID: 4b0b...
    *** Element info: {Using=xpath, value=//XCUIElementTypeOther[@name='Federal Motor Vehicle Standards Compliance Label']/XCUIElementTypeButton[1]}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)

0 个答案:

没有答案