XCUITest 不会用 Appium 和 iOS 重复相同的元素点击

XCUITest does not repeat same element click with Appium and iOS

我正在使用 Eclipse、Appium 和虚拟 iPhone 设备来尝试在应用程序上自动执行用户注册。但是,在同一个会话中点击同一个元素 2 次会导致第 2 次或更多次点击被忽略或失败。据我所知,Appium 没有抛出任何错误。输入 pin 代码的测试 ins 显示输入 10 个数字。

我已经确认,如果重复 none 个数字,每个元素都有效。如果任何数字重复,则点击提交到设备。

我还确认,通过在相同条件下手动执行此测试,我可以多次重复按相同的数字按钮而不会出现问题。所有点击均已注册。

更改暂停无关紧要。我已将其更改为每次点击最多 5 秒。点击速度似乎不是问题。使用的元素类型也没有。我也用 XCode.

试过这个

这是我使用固定代码注册服务的简单测试。

public static void RegisterUser() {
    
    //Click the register button.
    driver.findElement(By.id("registerButton")).click();
    
    //Enter Reg Code.
    ClickButton("**/XCUIElementTypeStaticText[`label == \"9\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"9\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"1\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"9\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"3\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"1\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"6\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"6\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"7\"`]");
    ClickButton("**/XCUIElementTypeStaticText[`label == \"0\"`]");
    
}

//Click the target and wait half a second.
public static void ClickButton(String element) {
    
    driver.findElement(MobileBy.iOSClassChain(element)).click();
    Pause(100);
}

//Pause the current thread.
public static void Pause(int pauseTime) {
    
    try {
        Thread.sleep(pauseTime);
    }
    catch(InterruptedException e) {
        
        e.printStackTrace();
        e.getMessage();
        e.getCause();
    }
}

这是 Appium 对同一元素进行 2 次点击后的输出。 这导致点击成功。

[HTTP] {"using":"-ios class chain","value":"**/XCUIElementTypeStaticText[`label == \"9\"`]"}
[debug] [W3C (47290369)] Calling AppiumDriver.findElement() with args: ["-ios class chain","**/XCUIElementTypeStaticText[`label == \"9\"`]","47290369-1558-4bae-98f7-ab0a3d0dc031"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id, css selector
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [XCUITest] Setting custom timeout to 12000 ms for 'findElement' command
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8100/session/7C394CAB-D8A7-4977-A463-97BE23B2671B/element] with body: {"using":"class chain","value":"**/XCUIElementTypeStaticText[`label == \"9\"`]"}
[debug] [WD Proxy] Got response with status 200: {"value":{"ELEMENT":"6A000000-0000-0000-7205-010000000000","element-6066-11e4-a52e-4f735466cecf":"6A000000-0000-0000-7205-010000000000"},"sessionId":"7C394CAB-D8A7-4977-A463-97BE23B2671B"}
[debug] [W3C (47290369)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"6A000000-0000-0000-7205-010000000000","ELEMENT":"6A000000-0000-0000-7205-010000000000"}
[HTTP] <-- POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element 200 92 ms - 137
[HTTP] 
[HTTP] --> POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6A000000-0000-0000-7205-010000000000/click
[HTTP] {"id":"6A000000-0000-0000-7205-010000000000"}
[W3C (47290369)] Driver proxy active, passing request on via HTTP proxy
[debug] [XCUITest] Executing command 'proxyReqRes'
[debug] [WD Proxy] Matched '/wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6A000000-0000-0000-7205-010000000000/click' to command name 'click'
[debug] [WD Proxy] Proxying [POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6A000000-0000-0000-7205-010000000000/click] to [POST http://127.0.0.1:8100/session/7C394CAB-D8A7-4977-A463-97BE23B2671B/element/6A000000-0000-0000-7205-010000000000/click] with body: {"id":"6A000000-0000-0000-7205-010000000000"}
[debug] [WD Proxy] Got response with status 200: {"value":null,"sessionId":"7C394CAB-D8A7-4977-A463-97BE23B2671B"}
[WD Proxy] Replacing sessionId 7C394CAB-D8A7-4977-A463-97BE23B2671B with 47290369-1558-4bae-98f7-ab0a3d0dc031
[HTTP] <-- POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6A000000-0000-0000-7205-010000000000/click 200 165 ms - 65

这个实际上并没有产生点击。但 Appium 认为确实如此。

[HTTP] {"using":"-ios class chain","value":"**/XCUIElementTypeStaticText[`label == \"9\"`]"}
[debug] [W3C (47290369)] Calling AppiumDriver.findElement() with args: ["-ios class chain","**/XCUIElementTypeStaticText[`label == \"9\"`]","47290369-1558-4bae-98f7-ab0a3d0dc031"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id, css selector
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [XCUITest] Setting custom timeout to 12000 ms for 'findElement' command
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8100/session/7C394CAB-D8A7-4977-A463-97BE23B2671B/element] with body: {"using":"class chain","value":"**/XCUIElementTypeStaticText[`label == \"9\"`]"}
[debug] [WD Proxy] Got response with status 200: {"value":{"ELEMENT":"6E000000-0000-0000-7205-010000000000","element-6066-11e4-a52e-4f735466cecf":"6E000000-0000-0000-7205-010000000000"},"sessionId":"7C394CAB-D8A7-4977-A463-97BE23B2671B"}
[debug] [W3C (47290369)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"6E000000-0000-0000-7205-010000000000","ELEMENT":"6E000000-0000-0000-7205-010000000000"}
[HTTP] <-- POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element 200 103 ms - 137
[HTTP] 
[HTTP] --> POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6E000000-0000-0000-7205-010000000000/click
[HTTP] {"id":"6E000000-0000-0000-7205-010000000000"}
[W3C (47290369)] Driver proxy active, passing request on via HTTP proxy
[debug] [XCUITest] Executing command 'proxyReqRes'
[debug] [WD Proxy] Matched '/wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6E000000-0000-0000-7205-010000000000/click' to command name 'click'
[debug] [WD Proxy] Proxying [POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6E000000-0000-0000-7205-010000000000/click] to [POST http://127.0.0.1:8100/session/7C394CAB-D8A7-4977-A463-97BE23B2671B/element/6E000000-0000-0000-7205-010000000000/click] with body: {"id":"6E000000-0000-0000-7205-010000000000"}
[debug] [WD Proxy] Got response with status 200: {"value":null,"sessionId":"7C394CAB-D8A7-4977-A463-97BE23B2671B"}
[WD Proxy] Replacing sessionId 7C394CAB-D8A7-4977-A463-97BE23B2671B with 47290369-1558-4bae-98f7-ab0a3d0dc031
[HTTP] <-- POST /wd/hub/session/47290369-1558-4bae-98f7-ab0a3d0dc031/element/6E000000-0000-0000-7205-010000000000/click 200 175 ms - 65

我可以想象这种情况,当第一次点击后你有多个元素,位于

**/XCUIElementTypeStaticText[`label == \"9\"`]

(例如,因为出现了带有标签 9 的新内容..)

然后下一次点击转到找到的第一个元素,但它不是按钮。

始终尝试单击列表中最后找到的元素。

P. S. 你的 appium 日志没有问题。