Showing posts with label findelements. Show all posts
Showing posts with label findelements. Show all posts

Tuesday, April 14, 2015

How to play with Web table in Selenium Webdriver ?

Web table is a different type of web element and we can not directly get all data in one variable.
To access web table data we need to locate web table using findelement method and then identified all the tr tags using findelements method.
Code for the same as below.

WebDriver driver =  new InternetExplorerDriver();
WebElement table = driver.findElement(By.id("tableid));
List<WebElement> tablerows = table.findElements(By.tagName("tr")); // To get all Rows

int rowcount  =  tablerows.size();  \\To get count of total rows

for (WebElement tablerow : tablerows )
{
tablerowindex = 0;
     List <WebElement> tablecolumns = tablerow.findelements(By.tagName("td"));
     int columncount = tablecolumns.size();
     for (WebElement tablecolumn : tablecolumns)
     {




      }



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.
    }