Method to Check Page Loaded before performing any actions in WebDriver
- June 7th, 2011
- By Vemu
- Write comment
Use this code instead of using WaitForPageLoad in your page classes.
this will make sure what ever Element locator you are entering is loaded before it performs any action related to that page from your test case.
So best way to put it is add a Page element which will load last on the page t make sure the page is completely loaded, this will reduce your wait statements or pause statement in the code which is not a great idea unless your test needs to do it.
@Override
public String getPageLoadedCheckElementLocator()
{
return ELEMENT_LOCATOR;
}
In your API which is common across all the pages add this
public CommonPage( WebDriver driver )
{
Driver = driver;
Wait< WebDriver > wait = new WebDriverWait( Driver, 90 );
wait.until( ElementVisible.byXPath( By.xpath( getPageLoadedCheckElementLocator() ) ) );
PageFactory.initElements( new AjaxElementLocatorFactory( driver, 60 ), this );
assertPageOk( driver );
}