Tuesday, March 24, 2015

How to play with findelements method in selenium webdriver ?

findElements method is used to locate multiple web element with same attribute.like all the element with type button on the page. It returns list of web element. if no element found then a empty list will be return. Like findelement it will not return null or raise any exception if no element found.

Code for play with findelements as below..

WebDriver driver = new InternetExplorerDriver();
List <webElement> elements = driver.findElements(By.className("button"));

for (WebElement element : elements )
   {
      String elmtext = element.getText();  / to get text from web element.
      boolean dis = element.isDisplayed(); //to check if web element is displayed.
    } 
 

 

No comments:

Post a Comment