Author Archive

XPATH Select element by Class

Issue: How to select an Xpath by element class which has multiple values or a long class name

Solution:  we can use Class Contains function

//span[contains(@class, 'active')]/input

you can use the above expression when you are asserting for certain element on the page

Assert for elementNotPresent on a page in Selenium WebDriver

There would be some scenarios where we need to assert that a particular emenet is not present or element is hidden on a page.

we need to do the following to assertElementNotPresent:
Create a class by Name: public class Element

Inside the class Element.java add the following method by name isHidden()
public static Boolean isHidden( WebDriver webDriver, By by )

{

try

{

WebElement element = webDriver.findElement( by );

return false;

}

catch ( NoSuchElementException e )

{

return true;

}

}

what the above does is it gets the Element not found exception and returns true.
How to implement the above class and method:

In the actual test add the following:

assertTrue( Element.isHidden( getWebDriver(),   By.xpath( xpathLocator ) ) );

How to assert for Page is OK

How to assert for page is ok or how to assert that there is no HTTP 500 error

 

private void assertPageOk( WebDriver driver )

{

boolean hasFailed = driver.getPageSource().contains( “HTTP ERROR 500″ )

|| driver.getPageSource().contains( “HTTP ERROR: 503″ );

 

assertFalse( “Failed due to server error.  Please check the server logs.”,

hasFailed );

}

 

Return top

INFORMATION

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