Appium Android Windows: driver.findElement(By.name()) не работает последовательно

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("")) не работает во второй раз?


person Tarumoy    schedule 06.03.2014    source источник


Ответы (1)


Проверьте с помощью Appium Inspector -> в поле «пароль» может не быть значения имени, установленного как «пароль», для доступа к нему.

Попробуйте получить доступ к элементу с помощью xpath, например:

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

Выполните следующие шаги, чтобы получить xpath или другие атрибуты с помощью Appium Inspector:

[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 :

введите здесь описание изображения

Вы увидите иерархию элементов вашего приложения, отображающую такие атрибуты, как имя, xPath, значение и т. д.

person Smriti    schedule 06.03.2014
comment
как //window[1]/scrollview[1]/secure[1] приходит этот путь? @смрити - person Tarumoy; 11.03.2014
comment
Я отредактировал свой комментарий выше и упомянул шаги для запуска Appium Inspector и просмотра атрибутов. - person Smriti; 11.03.2014
comment
Это плохая практика, любое небольшое изменение в макете нарушит ваш тест! используйте имя класса и текст, как упомянуто здесь stackoverflow.com/questions/22142219/ - person Shirane85; 10.11.2014