问题
Traditionally I always checked for the presence of objects in appium using:
int count = driver.findElements(by).size();
if (count == 0) {
Logger.LogMessage("ElementDoesNotExist: " + by, Priority.Medium);
return true;
} else {
Logger.LogMessage("ElementDoesExist: " + by, Priority.Medium);
return false;
}
However, I see there is now a isDisplayed() method:
driver.findElement(by).isDisplayed()
Anyone know which is best to use and why?
Thanks,
Charlie
回答1:
This is mostly Selenium question. When you use findElements you are looking for the presence element in DOM. However the element presence still not ensure that the element will visible. In order to verify the element display state you have to use isDisplayed method. For example in case the large page not all elements existing in the page DOM will be displayed.
Please see the details in W3C WebDriver specification
来源:https://stackoverflow.com/questions/30621713/appium-isdisplayed-vs-findelementsby-size