【问题标题】:XCUITest does not repeat same element click with Appium and iOSXCUITest 不会重复与 Appium 和 iOS 相同的元素点击
【发布时间】:2022-01-21 13:43:03
【问题描述】:

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

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

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

更改暂停无关紧要。我已将其更改为每次点击最多 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

【问题讨论】:

    标签: ios appium xcuitest


    【解决方案1】:

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

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

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

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

    尽量点击列表中最后找到的元素。

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

    【讨论】:

    • 你是对的。我没有考虑到屏幕上出现在同一元素父项下的新“9”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 2015-10-11
    • 2023-03-07
    • 2019-02-20
    • 2018-08-15
    • 2017-01-10
    相关资源
    最近更新 更多