I wrote a script for finding a name present in a particular column of List grid and it works fine accept sometimes its gives Error and my script fails.
e.g :- Store name ( 17' LCD Monitor & Dr. Grip Pens - Black) from the column Item into List Array and then trying to compare this value to the given text values.
The Code and error is given below:-
Code:-
public void getNumbersOfRows() {
List<String> lstr = new ArrayList<String>();
String text = "No are available with your current Settings.";
String text1 = "Text is loading your data...";
By test = ByScLocator.scLocator("//ATListGrid[ID="fundAssetsGrid"]/body/");
driver.waitForElementClickable(test);
driver.waitForGridDone(test);
WebElement fundAssetViewGridTable = driver
.findElement(ByScLocator.scLocator("//ATListGrid[ID="fundAssetsGrid"]/body/"));
List<WebElement> fundAssetViewGridTableAllRows = fundAssetViewGridTable.findElements(By.tagName("tr"));
for (WebElement row : fundAssetViewGridTableAllRows) {
if (row.getText().matches(text) || row.getText().matches(text1)) {
break;
} else if(row.getText().isEmpty()){
break;
}else{
List<WebElement> cells = row.findElements(By.tagName("td"));
for (WebElement cell : cells) {
lstr.add(cell.getText());
break;
}
}
}
for (WebElement row1 : fundAssetViewGridTableAllRows) {
try {
if(lstr.size() == 0){
if (row1.getText().matches(text) || row1.getText().matches(text1)) {
logger.info("Assets are Not Viewable in Asset Grid");
break;
}
}
} catch (NoSuchElementException e) {
logger.error("Assets are Viewable in Asset Grid");
}
driver.waitForElementClickable(test);
try {
if(lstr.size()!=0){
if (!(row1.getText().matches(text) || row1.getText().matches(text1))) {
logger.info("Assets are Viewable in Asset Grid");
logger.info("No of Assets present for this User is : " + (lstr.size()));
break;
}
}
} catch (NoSuchElementException e) {
logger.error("Assets are Not Viewable in Asset Grid");
}
}
lstr.clear();
}
Error:-
Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/sta...reference.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'pranav-laptop', ip: '1.8.0.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_66'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9454)
at <anonymous class>.Utils.getElementAt(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:9039)
at <anonymous class>.WebElement.getElementText(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12092)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:625)
Actually i am getting error at this position always (row.getText().matches(text) || row.getText().matches(text1)).
I am not refreshing page or its not done automatic then why i am getting error? Please help.
Waiting for your reply..
e.g :- Store name ( 17' LCD Monitor & Dr. Grip Pens - Black) from the column Item into List Array and then trying to compare this value to the given text values.
The Code and error is given below:-
Code:-
public void getNumbersOfRows() {
List<String> lstr = new ArrayList<String>();
String text = "No are available with your current Settings.";
String text1 = "Text is loading your data...";
By test = ByScLocator.scLocator("//ATListGrid[ID="fundAssetsGrid"]/body/");
driver.waitForElementClickable(test);
driver.waitForGridDone(test);
WebElement fundAssetViewGridTable = driver
.findElement(ByScLocator.scLocator("//ATListGrid[ID="fundAssetsGrid"]/body/"));
List<WebElement> fundAssetViewGridTableAllRows = fundAssetViewGridTable.findElements(By.tagName("tr"));
for (WebElement row : fundAssetViewGridTableAllRows) {
if (row.getText().matches(text) || row.getText().matches(text1)) {
break;
} else if(row.getText().isEmpty()){
break;
}else{
List<WebElement> cells = row.findElements(By.tagName("td"));
for (WebElement cell : cells) {
lstr.add(cell.getText());
break;
}
}
}
for (WebElement row1 : fundAssetViewGridTableAllRows) {
try {
if(lstr.size() == 0){
if (row1.getText().matches(text) || row1.getText().matches(text1)) {
logger.info("Assets are Not Viewable in Asset Grid");
break;
}
}
} catch (NoSuchElementException e) {
logger.error("Assets are Viewable in Asset Grid");
}
driver.waitForElementClickable(test);
try {
if(lstr.size()!=0){
if (!(row1.getText().matches(text) || row1.getText().matches(text1))) {
logger.info("Assets are Viewable in Asset Grid");
logger.info("No of Assets present for this User is : " + (lstr.size()));
break;
}
}
} catch (NoSuchElementException e) {
logger.error("Assets are Not Viewable in Asset Grid");
}
}
lstr.clear();
}
Error:-
Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/sta...reference.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'pranav-laptop', ip: '1.8.0.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_66'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9454)
at <anonymous class>.Utils.getElementAt(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:9039)
at <anonymous class>.WebElement.getElementText(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12092)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/pkothari/AppData/Local/Temp/anonymous1159940559189834308webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:625)
Actually i am getting error at this position always (row.getText().matches(text) || row.getText().matches(text1)).
I am not refreshing page or its not done automatic then why i am getting error? Please help.
Waiting for your reply..
Comment