4

I am trying to put selenium web driver wait, but always I am getting an exception "

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.id: mobileNo (tried for 20 second(s) with 100 milliseconds interval)".

I increased seconds to 100, then also getting the same problem, my id is correct.

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

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

learner
  • 331
  • 1
  • 9
  • 22

1 Answers1

1

As per the Java Docs of WebDriverWait Class if you want to change the Polling Interval you need to change it in the constructor as the constructor is as follows :

WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Moving forward as you are trying to invoke sendKeys() on the element you need to invoke the ExpectedConditions method elementToBeClickable.

So your code will be :

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");
System.out.println("navigated to new page"); 
WebDriverWait wait__mob = new WebDriverWait(d, 20);
try {
    System.out.println("Start"+new Date());
    wait__mob.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='form-group']//label[contains(.,'Mobile No.')]//following::div[1]/input[@class='form-control k-input' and @id='mobileNo' and @type='tel']"))).sendKeys("9999999999);
} catch (TimeoutException e) {
    System.out.println(e.toString());
} 
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thanks for ur reply,i tried ur code.but first time its worked and from second time its not working "org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //input[@class='form-control k-input' and @id='mobileNo'] (tried for 20 second(s) with 100 milliseconds interval)" – learner Apr 10 '18 at 09:32
  • i am not using any frames,only div..is could be reason?and when i try element visible test,some times element not visible,i think element appear after driver runs – learner Apr 10 '18 at 09:33
  • still same erro..org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //input[@class='form-control k-input' and @id='mobileNo'] (tried for 20 second(s) with 100 milliseconds interval) – learner Apr 10 '18 at 09:37
  • am not using frame.its full div only.we not using frame – learner Apr 10 '18 at 09:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168631/discussion-between-learner-and-debanjanb). – learner Apr 10 '18 at 10:08