Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve time out error in selenium webdriver with java?

My 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

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'

Any Help? I have already tried by increasing wait but doesn't work

like image 995
Ab123 Avatar asked Oct 29 '22 22:10

Ab123


1 Answers

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 :-

WebDriverWait wait = new WebDriverWait(driver,30);

WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#load_box input[name = 'username']")));
element.sendKeys("john");
like image 197
Saurabh Gaur Avatar answered Nov 15 '22 04:11

Saurabh Gaur