How can I write a wait_for_ajax call in selenium where the web page uses XMLHttpRequest based AJAX calls? -


i have select box calls xmlhttprequest based ajax call populate select box. want selenium wait till select box populated. have wait xmlhttprequest's readystate variable have value 4 means data populated.

in java: wait readystate change this:

    int trycount = 0;     boolean desiredresponsereceived = false;     while (desiredresponsereceived == false && trycount < 20) {         string readystate = (string) js.executescript("return xhr.readystate;");         if (readystate.equals("4")) {             desiredresponsereceived = true;         }         else {             thread.sleep(250);             trycount++;         }     }      if (desiredresponsereceived == false) {         driver.quit();     } 

one problem looking ready state is, page making more 1 xmlhttprequest. , won't know 1 which. if check after clicking relevant button (for example) fire off multiple requests. , there's no telling return first.

another option in case might instead wait options in select box change. in code above, might replace

string readystate = (string) js.executescript("return xhr.readystate;");      if (readystate.equals("4")) { 

with

list<webelement> options = driver.findelements(by.tagname("option"));      if (options.size() > 1) { 

or if don't know minimum number of options expect, test option particular attribute in list. or that.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -