Skip to content

[Bug] [PageObject] AppiumDriver.findElement() called twice #2034

Description

@jiangyitao
appium@2.1.3 
uiautomator2@2.29.9
java-client v8.5.1 / v8.6.0
class HomePage {

    @AndroidFindBy(accessibility = "Not Exists")
    WebElement loginBtn;

    HomePage(AppiumDriver driver) {
        // Timeout is Duration.ZERO or Duration.ofMillis(-1)
        PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ZERO), this);
    }

    void clickLoginBtn() {
        loginBtn.click();
    }
}

// Timeout is Duration.ZERO, but "/session/{sessionId}/element" called twice
new HomePage(driver).clickLoginBtn()
2023-10-09 22:44:36:292 - [HTTP] [HTTP] --> POST /session/6591db71-fb19-4037-861e-07c8f9d63252/element
2023-10-09 22:44:36:292 - [HTTP] [HTTP] {"using":"accessibility id","value":"Not Exists"}
2023-10-09 22:44:36:536 - [AndroidUiautomator2Driver@03be (6591db71)] Got response with status 404: {"sessionId":"2d2feb89-50bf-42e1-b196-b2c23e4f7a45","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
2023-10-09 22:44:36:543 - [HTTP] [HTTP] <-- POST /session/6591db71-fb19-4037-861e-07c8f9d63252/element 404 251 ms - 815
2023-10-09 22:44:36:543 - [HTTP] [HTTP] 
2023-10-09 22:44:37:057 - [HTTP] [HTTP] --> POST /session/6591db71-fb19-4037-861e-07c8f9d63252/element
2023-10-09 22:44:37:057 - [HTTP] [HTTP] {"using":"accessibility id","value":"Not Exists"}
2023-10-09 22:44:37:309 - [AndroidUiautomator2Driver@03be (6591db71)] Got response with status 404: {"sessionId":"2d2feb89-50bf-42e1-b196-b2c23e4f7a45","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
2023-10-09 22:44:37:311 - [HTTP] [HTTP] <-- POST /session/6591db71-fb19-4037-861e-07c8f9d63252/element 404 255 ms - 815

Activity

  1. theluckystrike commented on Oct 8, 2026

    @theluckystrike
    Contributor

    Confirmed on java-client 11.0.0 and fixed in #2472. I ran the page object from this issue against a local HTTP endpoint that records requests and answers no such element. Each click() sent 2 POST /element calls for Duration.ZERO and for Duration.ofMillis(-1), and a direct driver.findElement() sent 1.

    The second call comes from pagefactory.bys.builder.ByChained.findElement(). Every mobile annotation field resolves through ByChained, also with a single annotation, and it wrapped the lookup in new FluentWait<>(context) with the default 500 ms timeout and interval. That wait ran inside the one AppiumElementLocator already runs with the decorator timeout, which isn't visible to the user, so every attempt cost two lookups and at least 500 ms. With #2472 the chain runs once per attempt and the endpoint sees 1 call per click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions