I am completely new in selenium webdriver, I use version 2.31, testng 6.8 and fire tests in IE 8. I write my tests according to this scheme: I have test classes where I have methods with testng @Test annotation. It looks like this:
@Test(description="click Save Button ", dependsOnMethods = { "edit form" })
public void clickSaveButton(ITestContext context) {
page.clickSaveButton(driver);
}
Then, as you can see, I have a page class where the ids, xpaths, etc. are stored. It looks like this:
public void clickSaveButton(WebDriver driver){
Configuration.clickfoundElement(By.id(conf.get("saveButton")), driver);
}
conf is an object representing a properties file. Finally, I have a Configuration class where I am doing something like this:
public static void clickfoundElement(By by, WebDriver driver){
int attempts = 0;
while(attempts < 10) {
try {
driver.findElement(by).click();
break;
} catch(NoSuchElementException e) {
System.out.println("NoSuchElementException");
Reporter.log("NoSuchElementException<br/>");
if(attempts==9){
throw(e);
}
}
catch(StaleElementReferenceException e) {
System.out.println("StaleElementReferenceException");
Reporter.log("StaleElementReferenceException<br/>");
if(attempts==9){
throw(e);
}
}}
This prevents me from having a NoSuchElementException and a StaleElementReferenceException and works very well.
My first question is: is this approach right? The second and most important question is that from time to time I get the following problem:
Testng , "clickSaveButton" ( ) , clickSaveButton ( , ). "NoSuchElementException" (, -, html-). , NoSuchElementException , , ( , , ) , ( ) ?
.