Selenium Notes

Testing for text on page

 assertTrue( selenium.isTextPresent( "Some Text" ) );

Testing for ids or links

assertTrue( selenium.isElementPresent( "success.agent-deleted" ) );
assertTrue( !selenium.isElementPresent( "link=Test User Level 1" ) );

Testing if a radio button is selected or not

assertTrue( selenium.isElementPresent( "//input[@type='radio' and contains(@name, 'RadioGroup') and contains(@value, '0') and contains(@checked, true) ]" ));
assertTrue( selenium.isElementPresent( "//input[@type='radio' and contains(@name, 'RadioGroup') and contains(@value, '1') and contains(@checked, false) ]" ));

Testing to see if an input field has data

assertTrue( selenium.getValue( "xpath=//input[@id='points']" ).equals( "" ) );

h2 Testing to see if a Select drop down was chosen

assertTrue( selenium.getValue( "xpath=//select[@id='selectId']" ).equals( "SOMEVALUE" ) );

Selecting inputs

    selenium.click( "RADIO_SOME_VALUE" );
    selenium.select( "title", "index=1" );
    selenium.type( "firstName", "Test" );

Testing if a class is present

assertTrue( selenium.isElementPresent( 
  "xpath=//div[contains(@id, 'wrapper') and contains(@class, 'MyPageName')]" ) );

Helper 'click link' method

protected void clickAndWaitForPageToLoad( String elementId )
{
  try
  {
    selenium.click( elementId );
    selenium.waitForPageToLoad( PAGE_LOAD_TIME );
  }
  catch( SeleniumException ex )
  {
    // retry
    selenium.click( elementId );
    selenium.waitForPageToLoad( PAGE_LOAD_TIME );
  }
}
// Input with id of 'submit'.
clickAndWaitForPageToLoad( "submit" );

// An 'href' with the id of 'HOME'.
clickAndWaitForPageToLoad( "link=HOME" );
cd C:\dev\tools\selenium-server-1.0-beta-1
java -jar selenium-server.jar -interactive -port 4444
cd C:\dev\tools\selenium-server-1.0-beta-1
java -jar selenium-server.jar -interactive -port 4444 -browserSessionReuse

Starting Junit tests

-DsmokeTestBaseUrl=http://localhost -DsmokeTestCsscPort=9999 -DseleniumServerAddress=localhost -DseleniumServerPort=4444

Capture screenshot of exception

    catch( SeleniumException e )
    {
      selenium.captureScreenshot( "c:\\seleniumScreenshots\\exception-testFoo.png" );
    }

Browse Space

- Pages
- Blog
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content