Thursday, March 7, 2013

Radio But

1) Radio Button Clicked or Not Checking
WebElement element = driver.findElement(By.id("radio")).. 

steps first 
if radio button is not selected 
if(!element.isSelected()) 

element.click();//if not selected then through click event we could select radio button 
assertTrue(element.isSelected()); 


2) How to handle when the id of an object is changing continuously what we have to do?.

Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically. Each time id gets generated differently. So to handle this situation we use some JavaScript functions.

starts-with 

if your dynamic element's ids have the format <button id="continue-12345" /> where 12345 is a dynamic number you could use the following

XPath: //button[starts-with(@id, 'continue-')]  

contains 

Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element <input class="top suggest business"> can be located based on the ‘suggest’ class without having to couple it with the ‘top’ and ‘business’ classes using the following 

XPath: //input[contains(@class, 'suggest')].

3) Automate objects like dashboards or charts using selenium?

Use xpath for web element locators and there's a lot of plugins to make it easier, ex: if you are using firefox, you can use Firepath.


No comments:

Post a Comment