【发布时间】: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
【问题讨论】: