1
votes

I'm using Selenium WebDriver to enter text in 2 textboxe using java. I am able to enter text in the 1st text box but for the 2nd textbox I keep getting ElementNotVisibleException

HTML code..

<form name="form">
  <div class="form-group">
      <input name="name" type="text" class="form-control" ng-model="name" placeholder="Name*" required>
   </div>
   <div class="form-group">
       <input name="email" id="email" type="email" class="form-control" ng-model="email" ng-change="(form.email.$dirty && form.email.$valid) ? error='' : error='Please enter a valid email'" placeholder="Email*" required autofocus/>
    </div>
</form>

Java Code..

WebElement name = driver.findElement(By.name("name"));  
name.sendKeys("Sample Name");

WebElement signup_email = driver.findElement(By.name("email")); 
signup_email.sendKeys("[email protected]");

Error:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 19 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46' System info: host: 'Hp-PC', ip: '172.16.255.131', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79' Session ID: 2e7ab2fd-cd6b-428e-86e7-a4f7d8d737fa Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=47.0.1}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327) at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122) at src.tests.EmailSignUp.test(EmailSignUp.java:107) at src.tests.EmailSignUp.main(EmailSignUp.java:27)

Edit 1:

In the Browser Console the following classes are being automatically being populated by angular Js

Email_Console

I can't understand where I'm going wrong in case of 2nd textbox. Is the angular code causing problems?? Please Help..

1
As far as i can see, there is nothing wrong in your code. I guess its problem with the page it-self. As a work around you can try Explicit wait with expected condition of visibility.Siva
tried that..I'm getting a TimedOutException... :(Lucy
Are you able to enter values manually? May be you can try increasing time spanSiva
Pause the execution till entering the first text box value and then see the state of the element2 before trying to find it. May be it can give you some infoSiva
Have you checked if the selector for the element that is not visible matches multiple elements in the page? You can use a css like: [name=email]lauda

1 Answers

2
votes

May be when you are going to locate element, it would not be present on the DOM, You should try using WebDriverWait to wait until element present as below :-

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement name = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("name")));
name.sendKeys("Sample Name");

WebElement signup_email = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("email")));
signup_email.sendKeys("[email protected]");

Edited1 :- If you are still facing the issue during sendKeys(), I think some javascript embedded in your element which makes it invisible, in this case try to set value using JavascriptExecutor as below :-

WebElement signup_email = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("email")));
((JavascriptExecutor)driver).executeScript("arguments[0].value = '[email protected]'", signup_email);

Edited1:- If you want to make element visible, if not sure what exactly css work in your element but below is the generic way to make is visible as below :-

WebElement signup_email = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("email")));
signup_email = (WebElement)((JavascriptExecutor)driver).executeScript("arguments[0].style.visibility = 'visible'; return arguments[0];", signup_email);

//Now if it is visible then goto set value
signup_email.sendKeys("[email protected]");

Edited :- As I see this element is works with angularjs, try angularjs stuff to set value on this using JavascriptExecutor as below :

WebElement signup_email = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("email")));

((JavascriptExecutor).executeScript("angular.element(arguments[0]).scope().email = arguments[1]", signup_email, "[email protected]");

Hope it helps...:)