Method to Check Page Loaded before performing any actions in WebDriver

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 );

}

 

 

Selenium 2 – Grid release

Selenium 2 Grid release is now available.

Check out the official post here

Also Learn how to setup Grid from the following Instructions.

Now Automation life becomes much more easy for all Selenium users

Selenium WebDriver StaleElementReference Exception

I get this error when running my tests: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM

Scenario is :

The condition that I’ve had this problem with is something like: – Wait until there is a value in a table cell, under the heading ‘someHeader’, for table ‘tableLocator’, and if found return its row index. (I’m trying to see if an entity appears in the table by finding its ID, then I want to operate on that row). The twist is that I have to work with dynamic tables where the columns can be shown or hidden, so I cannot know the index of the column in advance. So first I have to find the index of the column and then get the <td>s with the value.

Solution:

That exception is thrown when you try to use a method of a WebElement that is not longer on the page. If your grid is dynamically loading data and you refresh the grid, any references to elements on that grid would be ‘stale’. Double check that the element you’re trying to reference is on the page in your tests, and you may need to re-instantiate the object.

Or

We get around this issue by doing something called WebdriverWrapper and WebElementWrapper.

What these wrappers do is handle the StaleElementException within and then use the locator to re-evaluate and get the new WebElement object. This way, you need to spread the code handling the exception all over your codebase and localize it to one class.

Return top

INFORMATION

Do not forget to leave a comment if you find the posts useful.
 
35353