android - Appium Android Windows : driver. findElement(By.name (""))不能连续工作

标签 android windows testcase appium

WebElement username=driver.findElement(By.name("username"));
username.sendKeys("test");
WebElement password=driver.findElement(By.name("password"));         
password.sendKeys("test");
WebElement loginBtn=driver.findElement(By.name("Login"));
loginBtn.click();       
WebElement backBtn=driver.findElement(By.tagName("Button"));
backBtn.click();

当我使用上述测试用例时,用户名运行成功,但在输入密码时显示以下错误。

debug: Appium request initiated at /wd/hub/session/71ed55ce-c3ae-46d8-9ce7-67452
0992c0a/element/1/value
debug: Request received with params: {"id":"1","value":["test"]}
info: Pushing command to appium work queue: ["element:setText",{"elementId":"1",
"text":"test"}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"element
:setText","params":{"elementId":"1","text":"test"}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: setText
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
info: Responding to client with success: {"status":0,"value":true,"sessionId":"7
1ed55ce-c3ae-46d8-9ce7-674520992c0a"}
POST /wd/hub/session/71ed55ce-c3ae-46d8-9ce7-674520992c0a/element/1/value 200 26
53ms - 89b
debug: Appium request initiated at /wd/hub/session/71ed55ce-c3ae-46d8-9ce7-67452
0992c0a/element
debug: Request received with params: {"using":"name","value":"password"}
info: Pushing command to appium work queue: ["find",{"strategy":"name","selector
":"password","context":"","multiple":false}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","
params":{"strategy":"name","selector":"password","context":"","multiple":false}}

info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: find
info: [BOOTSTRAP] [debug] Finding password using NAME with the contextId:
info: [BOOTSTRAP] [info] Returning result: {"value":"No element found","status":
7}
info: Responding to client with error: {"status":7,"value":{"message":"An elemen
t could not be located on the page using the given search parameters.","origValu
e":"No element found"},"sessionId":"71ed55ce-c3ae-46d8-9ce7-674520992c0a"}
POST /wd/hub/session/71ed55ce-c3ae-46d8-9ce7-674520992c0a/element 500 783ms - 22
3b

为什么 findElement(By.name("")) 第二次不起作用?

最佳答案

使用 Appium Inspector 检查 -> 字段“密码”可能没有任何名称值设置为“密码”以访问它。

尝试使用 xpath 访问元素,例如:

  WebElement password = driver.findElement(By.xpath("//window[1]/scrollview[1]/secure[1]"));
  password.click();
  password.sendKeys("psswrd");

按照以下步骤使用 Appium Inspector 获取 xpath 或其他属性:

[1] Launch Appium server.
[2] Check the check box 'App Path'.
[3] Click on the 'Choose' button and select your .app file location from your local, e.g. xyz.app
[4] Now click on the 'Launch' button . Once appium server is launched, the blue color icon besides the 'Launch' button is enabled.
[5] Click on the blue color icon, it will open up the appium inspector and simulator with your application :

enter image description here

您将看到您的应用的元素层次结构,显示名称、xPath、值等属性。

关于android - Appium Android Windows : driver. findElement(By.name (""))不能连续工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22223814/

相关文章:

android - 如何将实时流媒体视频从手机制作到网站页面

环境变量中的 Windows 控制台宽度

python - 在 python 3 中导入 win32com 时遇到问题

java - Selenium:动态按钮和类?

algorithm - 礼品包装算法(贾维斯算法)计算凸包的最坏情况是什么?

android - 无法使所有模型的 Retrofit2 接口(interface)通用

java - android - 带有 HashMap 的 ListView 适配器显示不正确

java - 存储JSON对象: SQLite vs serialization to disk

windows - rdesktop 中正确的键盘映射问题

c# - 在 ValueSourceAttribute 上指定的 sourceName 必须引用非 null 静态字段、属性或方法