Appium:“使用给定的搜索参数无法在页面上定位元素"错误
我是 Appium 的新手,一直在尝试为 Android 自动化转换计算器应用程序.尝试查找 EditText 元素时,收到错误org.openqa.selenium.NoSuchElementException:无法使用给定的搜索参数在页面上定位元素".使用 Appium 1.0.0 版和 Android 4.3
I am new to Appium and have been trying to automate the Conversion Calculator app for Android. Am getting the error "org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters", when trying to find a EditText element. Using Appium ver 1.0.0 and Android 4.3
以下是我的代码:
List<WebElement> textViews = driver.findElements(By.className("android.widget.TextView"));
for (i=0; i<textViews.size(); i++) {
if(textViews.get(i).getText().toLowerCase().contains("memory")) {
textViews.get(i).click();
}
}
Thread.sleep(5000);
WebElement editText = driver.findElement(By.className("android.widget.EditText"));
editText.sendKeys("123");
甚至通过 ID findElement 也不起作用.请让我知道我在这里做错了什么,或者我是否需要提供更多详细信息.
Even findElement by ID is not working. Please let me know what I am doing wrong here or if I need to provide more details.
我会用driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
而不是 Thread.sleep(5000)
.
尝试使用较新版本的Appium,我已经改进了很多.你可以在这里下载最新版本的 Appium 和 Appium 客户端:http://appium.io/downloads.html
Try to use a newer version of Appium, I's been improved a lot. You can download the latest version of Appium and Appium clients here:http://appium.io/downloads.html
但要小心,因为在较新的版本中,如果搜索结果不止一个,则 findElement 会抛出异常.
But be careful because in the newer version the findElement throws an Exception if there are more then one result of the search.
我会在评论中写下这个,但我没有足够的声誉:/
I would write this in a comment but I've not enough reputation :/