Generally selenium WebDriver handles software app's page loading or wait for page to load past times It self If yous convey used Implicit Wait In your software automation test. But many on evolution sites convey a page loading Issues as well as It Is taking to a greater extent than or less fourth dimension for page to charge on every software essay iteration. So to a greater extent than or less times your essay volition run without whatsoever Issue as well as to a greater extent than or less times It volition hold out unable to institute to a greater extent than or less elements due to the page loading Issue.
I convey a solution for such Issue If whatsoever 1 facing It. We tin role bellow given javascript syntax In our software automation essay to cheque (loading) status of page. It volition furnish "complete" when page Is loaded completely.
document.readyState
We convey already learnt how to execute javascript In selenium software automation essay earlier.You volition honour few of the examples on THIS LINK. Javascript execution syntax to acquire page loading status In webdriver Is every bit bellow. It volition cheque Page cook status for us.
JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("return document.readyState").toString().equals("complete");
So nosotros tin cheque page cook status afterwards every 1 minute using for loop every bit shown In bellow example.
Once page Is ready, It volition kickoff taking actions on page.
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; world flat checkPageReady { WebDriver driver; @BeforeTest world void setup() throws Exception { driver = novel FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(" "); } @Test world void calc() { //Call this percentage to await for page to ready. checkPageIsReady(); //Once page Is ready/loaded, Bellow given steps volition hold out executed. driver.findElement(By.xpath("//input[@id='1']")).click(); driver.findElement(By.xpath("//input[@id='plus']")).click(); driver.findElement(By.xpath("//input[@id='5']")).click(); driver.findElement(By.xpath("//input[@id='equals']")).click(); } world void checkPageIsReady() { JavascriptExecutor js = (JavascriptExecutor)driver; //Initially bellow given if status volition cheque cook acre of page. if (js.executeScript("return document.readyState").toString().equals("complete")){ System.out.println("Page Is loaded."); return; } //This loop volition rotate for 25 times to cheque If page Is cook afterwards every 1 second. //You tin supercede your value amongst 25 If yous wants to Increase or decrease await time. for (int i=0; i<25; i++){ endeavour { Thread.sleep(1000); }catch (InterruptedException e) {} //To cheque page cook state. if (js.executeScript("return document.readyState").toString().equals("complete")){ break; } } } }
This way, You tin cheque or wait for page to load In selenium webdriver software automation test.
http://www.software-testing-tutorials-automation.com/