Automating UI Elements in SlickGrid using Webdriver

873 views
Skip to first unread message

ramesh

unread,
Mar 23, 2012, 10:16:01 AM3/23/12
to webdriver
Hi All,

I'm using Selenium webdriver to automate the web application
containing ui elements in slickgrid .https://github.com/mleibman/
SlickGrid/wiki

To read the column values from the slickgrid (selenium webdriver with
c#) i'm traversing the grid through XPath and reading the column
values using findelement(by.xpath(" ").text

Slickgrid table looks something like below.

<div class="grid-canvas" tabindex="0" hidefocus="" style="width:
665px; height: 271px; ">

<div class="ui-widget-content slick-row even" row="0" style="top:
0px">
<div class="slick-cell lr l0 r0">value</div>
<div class="slick-cell lr l1 r1">value</div>
<div class="slick-cell lr l2 r2">value</div
><div class="slick-cell lr l4 r4">value</div>
<div class="slick-cell lr l3 r3">value</div>
</div>
<div class="ui-widget-content slick-row odd" row="1" style="top:
25px">
<div class="slick-cell lr l0 r0">value</div>
<div class="slick-cell lr l1 r1">value</div>
<div class="slick-cell lr l2 r2">value</div>
<div class="slick-cell lr l3 r3">value</div>
<div class="slick-cell lr l4 r4">value</div></div>

Is there any extension or libraries to read the column values (in
this eg :value ) and getting rowcount apart from using xpath like //
div[4]/div/div/div[4] ?

Thanks in advance.
Ramesh

Dhamotharan K

unread,
Jan 14, 2017, 12:40:08 AM1/14/17
to webdriver
There is no libraries as far as I know but you can still automate. Here is the sample code:

public ArrayList<String> getDataFromListMaintenance(String ColumnName) {
ArrayList<String> sllineitems = new ArrayList<String>();
Boolean statusIterate = false;
List<WebElement> weitems = null;
try {
// By default 100 line items will be there on a page and 3 times we
// are iterating to capture all web elements due to slick view
// limitation
for (int a = 0; a <= 3 && !statusIterate; a++) {
weitems = driver
.findElements(By
.xpath("//*[contains(@style,'width: 100%; overflow: auto; outline: 0px none; position: relative; height: 425px;')]//*[contains(@style,'top:')]"));

for (int i = 1; i < weitems.size(); i++) { // i- starts from
// 1since first row
// is always blank
if (ColumnName.equalsIgnoreCase("VALUES")) {
WebElement e1 = weitems.get(i).findElement(
By.xpath(".//div[1]"));
sllineitems.add(e1.getText().toString());
} else if (ColumnName.equalsIgnoreCase("DESCRIPTION")) {
WebElement e2 = weitems.get(i).findElement(
By.xpath(".//div[2]"));
sllineitems.add(e2.getText().toString());
} else if (ColumnName.equalsIgnoreCase("BOTH")) {
WebElement e1 = weitems.get(i).findElement(
By.xpath(".//div[1]"));
WebElement e2 = weitems.get(i).findElement(
By.xpath(".//div[2]"));
sllineitems.add(e1.getText().toString() + ":"
+ e2.getText().toString());
System.out.println((e1.getText().toString() + ":" + e2
.getText().toString()));
}

}

if (weitems.size() >= 36) {

// WebElement element = driver
// .findElement(By
// .xpath("//*[contains(@style,'width: 100%; overflow: auto; outline: 0px none; position: relative; height: 425px;')]//*[contains(@style,'top:875')]"));
System.out.println("//div[contains(text(),'"
+ (sllineitems.get(sllineitems.size() - 1)
.substring(0, 21)) + "')]");
WebElement element = driver.findElement(By
.xpath("//div[contains(text(),'"
+ (sllineitems.get(sllineitems.size() - 1)
.substring(0, 21)) + "')]"));

((JavascriptExecutor) driver).executeScript(
"arguments[0].scrollIntoView(true);", element);
// Thread.sleep(1000);
System.out.println("SIZE:" + weitems.size());

} else {
statusIterate = true;
}
weitems.clear();
}

removeDuplicates(sllineitems);

} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
}
return sllineitems;
Reply all
Reply to author
Forward
0 new messages