Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking presence of element in regular time interval Selenium
    text
    copied!<p>I am using selenium framework where I am checking for the completion of load of three heading tags with id say head1, head2, head3.The total wait time for which I want to wait to ensure the load of all the three heading tags is 12 seconds.The loading of three heading tags can happen either in any time 1,2,3,4... Seconds.</p> <p>Now I want to do a regular check for every 2 seconds till 12 seconds to check if all three heading tags are loaded so I can jump to other part of code. I have tried few code but unable to figure the exact code which meets my requirement.</p> <p>The below code contains wait for heading tags to get loaded which checks for h1 tag every 2 seconds till 12 seconds.</p> <p><strong>Selenium Code</strong></p> <pre><code>WebDriver driver = new FirefoxDriver(); driver.get("http://URL.com/Sample.jsp"); driver.manage().window().maximize(); Wait&lt;WebDriver&gt; wait = new FluentWait&lt;WebDriver&gt;(driver) .withTimeout(12, TimeUnit.SECONDS) .pollingEvery(2, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); WebElement foo = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("h1"))); if((driver.findElement(By.id("h1")).getText()).length() &gt;0) System.out.println("Element Loaded"); else System.out.println("Element yet to be Loaded"); </code></pre> <p><strong>Html Code</strong></p> <pre><code>&lt;script type="text/javascript"&gt; myFunction(); function myFunction() { setTimeout(function(){populateDiv1();},3000); setTimeout(function(){populateDiv2();},6000); setTimeout(function(){populateDiv3();},9000); } function populateDiv1() { document.getElementById('div1').innerHTML = "&lt;h1 id='head1'&gt;Div1 Loaded&lt;/h1&gt;"; } function populateDiv2() { document.getElementById('div2').innerHTML = "&lt;h1 id='head2'&gt;Div2 Loaded&lt;/h1&gt;"; } function populateDiv3() { document.getElementById('div3').innerHTML = "&lt;h1 id='head3'&gt;Div3 Loaded&lt;/h1&gt;"; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="div1"&gt; &lt;/div&gt; &lt;div id="div2"&gt; &lt;/div&gt; &lt;div id="div3"&gt; &lt;/div&gt; &lt;/body&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload