[英]How to solve time out error in selenium webdriver with java?
My Html 我的Html
<form id="load_form" class="ajaxsubmit" method="post" action="ajax.php">
<input type="hidden" value="register" name="action">
<h3>Registration Form</h3>
<img id="loader" width="20" height="20" style="display:none;" src="images/loader.gif">
<p id="alert"></p>
<fieldset>
<fieldset>
<fieldset>
<fieldset>
<fieldset>
<fieldset>
<label>Username:</label>
<input type="text" required="" name="username">
</fieldset>
My Java Code 我的Java代码
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='username']")));
element.sendKeys("john");
Getting Below Error 低于错误
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for visibility of element located by By.xpath: //input[@name='username'] Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:01:03'
线程“main”中的异常org.openqa.selenium.TimeoutException:30秒后超时,等待By.xpath定位元素的可见性://输入[@ name ='username']构建信息:版本:'2.53.0 ',修订版:'35ae25b',时间:'2016-03-15 17:01:03'
Any Help? 任何帮助? I have already tried by increasing wait but doesn't work
我已经尝试过增加等待但不起作用
Actually there are two input
elements present with the same name username
where one is hidden and another is visible and you are intracting with first one which is not visible on the page that's why you are unable to locate, try using cssSelector
as below :- 实际上有两个
input
元素同名username
,其中一个是隐藏的,另一个是可见的,你正在使用在页面上看不到的第一个input
元素,这就是你无法找到的原因,尝试使用cssSelector
,如下所示: -
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#load_box input[name = 'username']")));
element.sendKeys("john");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.