java - Alternative way to replace 'Thread.sleep(5000)' -


is there alternative way replace 'thread.sleep(5000)'? currently, commentsbutton clicks once , move on codes repliesbutton though there other elements commentsbutton? thought because of 'thread.sleep(5000)' page not done loading.

          if(commentsbutton.size() > 0) {                 commentsbutton.get(0).click(); //click on button if found                 thread.sleep(5000); //pause 5 seconds           }                      else clickmore = false;            if(repliesbutton.size() > 0) {                  repliesbutton.get(0).click(); //click on button if found                  thread.sleep(5000); //pause 5 seconds            }            else clickmore = false;              if(seemorebutton.size() > 0) {                   seemorebutton.get(0).click(); //click on button if found                   thread.sleep(5000); //pause 5 seconds            }            else clickmore = false;            } 

you can use loop this, have understand, loop use process resources during execution. think, thread.sleep preffered in case anyway...

long = system.currentmillisec();    long executionduration = + 5000; while(now < executionduration){     = system.currentmillisec(); } 

but said

the commentsbutton clicks once , move on codes

it seems, need ta add additional loop on elements of commentsbutton collection, click comments buttons have before go repliesbuttons. clicking 1 button, commentsbutton.get(0).click();

if(commentsbutton.size() > 0) {     (webelement element : commentsbutton) {         element.click(); //click on button if found         thread.sleep(5000); //pause 5 seconds     } }            

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -