java - Selenium webdriver code takes time to exit while loop -


the code have works when while loop breaks, takes 20 seconds what's below while loop execute.

here code:

driver.manage().timeouts().pageloadtimeout(3, timeunit.seconds);     try {         driver.get("website");     } catch (timeoutexception e) {          string x = driver.findelement(by.cssselector("b")).gettext();            driver.get("website");         driver.findelement(by.id("479510558845313")).sendkeys(instagramaievx.spamusernameinput);        driver.findelement(by.id("263795143794707")).sendkeys(instagramaievx.spamcommentinput);          driver.findelement(by.id("u_0_4")).sendkeys(x);         driver.findelement(by.id("u_0_5")).click();         while (true){             webelement button = null;             try {               button = driver.findelement(by.cssselector("a[action='cancel']"));             } catch (nosuchelementexception ex){               break;              }             if (button.isdisplayed() == false) {               break;             }              driver.navigate().refresh();              timeunit.seconds.sleep(5);             driver.findelement(by.id("479510558845313")).sendkeys(instagramaievx.spamusernameinput);              driver.findelement(by.id("263795143794707")).sendkeys(instagramaievx.spamcommentinput);              driver.findelement(by.id("u_0_4")).sendkeys(x);             driver.findelement(by.id("u_0_5")).click();         }          killfirefox();     } 

any idea of what's causing ~20 second delay.

decreasing implicit wait timeout duration not solution. problem in code findelement() waits whatever implicit wait duration set, useless if element not there, not solution either.

if expect element not present (or possibly not present), it's idea temporarily disable implicit wait.

in case, findelement() calls before while loop starts, there's no more need implicit wait @ point, because can sure document has been loaded. set implicit wait 0 seconds before while loop , 30 seconds afterwards , you're fine.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -