Verify a flexigrid columns are sorted in Ascending/DEscending order

970 views
Skip to first unread message

Priya P

unread,
Jan 18, 2015, 10:13:29 PM1/18/15
to seleniu...@googlegroups.com
I have a flexigrid with rows and columns, how do I verify that the columns are sorted using Selenium Webdriver

Priya P

unread,
Jan 20, 2015, 6:50:23 PM1/20/15
to seleniu...@googlegroups.com
Anyone???

Following is my code, where I get list of data from the webtable. After I get the data How do I implement sort after I get the list?



import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import junit.framework.Assert;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class getdatafromawebtable {
static FirefoxDriver driver = new FirefoxDriver();
String BaseURL = “https://qa.example.com/”;
int iwait = 3000;

@Test
public void sorting() throws Exception {
driver.get(BaseURL);
driver.findElement(By.id(“Username”)).sendKeys(“username”);
driver.findElement(By.id(“Password”)).sendKeys(“pswd”);
driver.findElement(By.xpath(“//input[@type=’input’]”)).click();
driver.findElement(By.xpath(“"xpath)).click();

WebElement table = driver.findElement(By.xpath(“//descendant::table[4]”));

List rows = table.findElements(By.tagName(“tr”));
int row_count = rows.size();
System.out.println(“Total rows is ” + row_count);
IteratorI1 = rows.iterator();

while(I1.hasNext()){
WebElement data = I1.next();

List columns= data.findElements(By.tagName(“td”));
Iterator I2=columns.iterator();
while(I2.hasNext()){
WebElement text=I2.next();
String columndata=text.getText();
System.out.print(” “);
System.out.print(columndata);
System.out.print(” “);
}
System.out.println(“”);
}

}

}

PeterJeffreyGale

unread,
Jan 20, 2015, 7:04:53 PM1/20/15
to seleniu...@googlegroups.com
You've done the Selenium bit - iterating over the columns and getting the text.

The rest is simple logic and basic coding: keep track of the text of both the current colkumn and the previoud column; compare the current column text to the previous column text alphabetically, as you iterate over each colmn, and break out of the loop if any column is less than (I.e. before) the previous column. If you get to the end of the loop, all the columns are in order.

If you can't write the code for yourself, get one of your developers to help.

Red

unread,
Jan 13, 2017, 5:18:54 AM1/13/17
to Selenium Users
Hi All,

I am new to the selenuim and want to know that how to check my date column in descending order (Latest first)

Any help?

Thanks in advance
R
Reply all
Reply to author
Forward
0 new messages