How to work on a Radio Button in Selenium WebDriver.
- March 20th, 2011
- Posted in Selenium . Uncategorized . webdriver . XPATH
- By Vemu
- Write comment
Because of Ajax on websites sometimes we need to reload the elements so we need to try and locate the element on the page so we use a for loop
public static RadioButton getRadio( WebDriver driver, String label, String locator )
{
RadioButton radio = null;
int i = 0;
while ( true )
{
i++ ;
try
{
radio = new RadioButton( label,
driver.findElement( By.xpath( locator ) ) );
break;
}
catch ( StaleElementReferenceException e )
{
sleep( 50 );
}
if ( i > 10 )
{
System.out.println( “[WARNING] Unable to find RadioButton 10 attempts” );
break;
}
}
return radio;
}
No comments yet.