我无法找到一个元素,尽管使用appium inspector使用我在代码中使用的相同定位器来定位元素。
By by = By.xpath("//UIATextView[@value='hey!!!!!']");
boolean result;
do{
device.swipeUp();
result = waitUntil(ExpectedConditions.visibilityOfElementLocated(by));
}while (!result);
我的waitUntil定义为:
public boolean waitUntil(ExpectedCondition<WebElement> condition){
WebDriverWait wait = new WebDriverWait(device.getDriverWrapper().getIosDriver(),5);
wait.withTimeout(1,TimeUnit.SECONDS);
try {
wait.until(condition); // i wait until the condition will be met (with a time out of 1 seconds) and return true
return true;
}
catch (Exception e) {
return false; // if after the timeout of 1 seconds has reached then i retrun false
}
}
我看到虽然提供了元素,但设备仍然会向上滑动。 有什么想法吗?
答案 0 :(得分:0)
如果您期待等到元素位于屏幕上,您可以使用类似于以下代码段的内容:
By by = By.xpath("//UIATextView[@value='hey!!!!!']"); //any locator strategy
new WebDriverWait(driver, timeToWaitInSeconds)
.until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver d) {
return driver.findElement(by);
}
});
或者更简单的东西也可以解决问题:
By by = By.xpath("//UIATextView[@value='hey!!!!!']");
result = driver.findElement(by);
boolean result;
while (!result){
device.swipeUp();
result = driver.findElement(by);
}