java - Time out after waiting for visibility of element -


i'm having trouble consistently selecting flight return date travel search site. works, of time doesn't , i'm pretty stumped @ point. error i'm receiving is: exception in thread "main" org.openqa.selenium.timeoutexception: timed out after 20 seconds waiting visibility of element located by.id: ui-datepicker-div

i've set few wait statements date elements i'm clicking against, i'm still receiving error. i'm trying find solution can avoid using thread.sleep. appreciated!

here script:

public class datepickertest {     private static webdriver driver = new firefoxdriver();     static webdriverwait wait = new webdriverwait(driver, 20);      public static void main(string[] args) {             driver.get("http://lowfares.com");         selectdepartdate(2016, 5, 18);         selectreturndate(2016, 5, 21);     }      public static void selectdepartdate(int year, int month, int day) {         month--; // replacing 0 based index         integer.tostring(year);         integer.tostring(month);         integer.tostring(day);          wait.until(expectedconditions.visibilityofelementlocated(by.id("depart_date")));          // click on text box open date picker calendar         driver.findelement(by.id("depart_date")).click();          // close pop window         string parentwindowhandler = driver.getwindowhandle();         string subwindowhandler = null;         set<string> handles = driver.getwindowhandles();         iterator<string> iterator = handles.iterator();         while (iterator.hasnext()) {             subwindowhandler = iterator.next();         }         driver.switchto().window(subwindowhandler);         driver.close();         driver.switchto().window(parentwindowhandler);          // wait calendar interface appear         wait.until(expectedconditions.visibilityofelementlocated(by.id("ui-datepicker-div")));          // select depart date         driver.findelement(by.xpath("//td[contains(@data-month, " + month + ") , contains(@data-year, " + year + ")]//a[contains(text(), " + day + ")]")).click();     }      public static void selectreturndate(int year, int month, int day) {         month--; // replacing 0 based index         integer.tostring(year);         integer.tostring(month);         integer.tostring(day);          wait.until(expectedconditions.visibilityofelementlocated(by.id("return_date")));          // click on text box open date picker calendar         driver.findelement(by.id("return_date")).click();          // wait calendar interface appear         wait.until(expectedconditions.visibilityofelementlocated(by.id("ui-datepicker-div")));          // select return date         driver.findelement(by.xpath("//td[contains(@data-month, " + month + ") , contains(@data-year, " + year + ")]//a[contains(text(), " + day + ")]")).click();     } } 

i see few problems:

  1. depart_date div, shouldn't clicking on it, instead click on <input id="depart":

    driver.findelement(by.id("depart")).click(); 
  2. not sure popup window doing (i didn't popup). in case, check first popup window there:

    ... set<string> handles = driver.getwindowhandles(); (string windowhandle : handles) {      subwindowhandler = windowhandle; } if(subwindowhandler != null && !subwindowhandler.equals(parentwindowhandler) {     driver.switchto().window(subwindowhandler);     driver.close();     driver.switchto().window(parentwindowhandler); } ... 
  3. if did close popup, , switched main window, need make sure calendar still open; if not, reopen it:

    public void iscalendarvisible() {     try {         webelement element = wait.until(expectedconditions.visibilityofelementlocated(by.id("ui-datepicker-div")));         return true;     } catch (timeoutexception e) {         return false; } 

    and under

    // wait calendar interface appear if(!iscalendarvisible()) {     // try reopen calendar     driver.findelement(by.id("depart")).click(); } 
  4. neat-picking: following doesn't anything:

    integer.tostring(year); integer.tostring(month); integer.tostring(day); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -