【发布时间】:2018-09-18 16:18:50
【问题描述】:
我正在尝试让 selenium web 驱动程序等待,但我总是遇到异常“
org.openqa.selenium.TimeoutException:预期条件失败:等待 By.id 定位的元素的可见性:mobileNo(尝试 20 秒,间隔 100 毫秒)”。
我将秒数增加到 100,然后也遇到了同样的问题,我的 id 是正确的。
WebDriver d = new ChromeDriver();
d.get("http://myurlOne");
WebElement username = d.findElement(By.id("username_id"));
username.sendKeys("123");
WebElement password = d.findElement(By.id("password_id"));
password.sendKeys("123");
d.findElement(By.id("loginButton")).click();
System.out.println("logged in successfully");
d.get("http://navigatedurl");
JavascriptExecutor js = (JavascriptExecutor)d;
System.out.println("navigated to new page");
WebDriverWait wait__mob = new WebDriverWait(d, 20);
try {
System.out.println("Start"+new Date());
wait__mob .pollingEvery(100,TimeUnit.MILLISECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.id("mobileNo")));
d.findElement(By.id("mobileNo")).sendKeys("99999999999);
} catch (TimeoutException e) {
// TODO: handle exception
System.out.println(e.toString());
}
分区代码:
<div class="form-group">
<label class="col-xs-5 control-label" for="mobileNo">Mobile No.</label>
<div class="col-xs-6 leftpadding-none">
<input type="tel" class="form-control k-input" id="mobileNo"
name="inputmobileNo" placeholder="" maxlength="10"> <!--required
pattern="\d{10}" validationMessage="Mobile No. is Required"-->
</div>
【问题讨论】:
-
页面的html是什么?这是您需要检查的真实 div 吗?
-
您收到异常是因为您没有正确处理异常并且元素在 20 秒后未定位。
-
它真正的 div..我检查了 dat
-
是的元素在 20 秒后没有找到,我也尝试了 100 秒,den 也一样..
-
检查它是否在框架内?
标签: selenium selenium-webdriver