-2

My code is as under:

FirefoxDriver driver = new FirefoxDriver();

driver.get(url);

//element is not found here

driver2.findElement(By.xpath("//*/div/div[2]/div/div/div[2]"));

//i want to continue the script execution 

//but the scripts comes to 

driver2.findElement(By.xpath("//*/div/div[2]/div/div/div[2]")); 

//and shows me fail

driver2.findElement(By.xpath("//*/div/div[2]/div"));
  • Here , Logic is most important. Use java concept like If, Else, exception, Selenium methods like IsDisplayed() etc. This question is very broad and depends on implantation. – Sagar007 Dec 11 '17 at 6:30
  • Quite simple- use Assert, Verify concepts, exception handling keywords, if else condition at particular steps.. – Bharat Mane Dec 11 '17 at 16:40
0

To continue execution there are many ways, you can use "Verify" method and If condition. (if you are using java) fore more info click here

  • I have tried with try catch block for continue the script execution but the scripts is not failing it is showing pass..How to make the script fail when the element is not found ... – John Dec 11 '17 at 6:40
  • @John On catch add (NoSuchElement Exception e){ S.o.p("Test failed")}; – sameer joshi Dec 19 '17 at 9:30
0

Many frameworks have features to do it. TestNG's softAssert, for instance.

A solution independent of frameworks is to implement one yourself. You will need an object which holds the falling assertions and has a method to throw all of them somehow.

Your test:

try{
    assert.....
} catch(AssertError e) {
    assertHolder.hold(e);
}
(More asserts here....)
assertHolder.throwErrors();

assertHolder's class:

hold(AssertError e) {
   this.errors.add(e);
}

throwErrors() {
   errorMsg = "";
   for(error in this.errors) {
       errorMsg += error.msg; // Or accumulate these messages as you want
   }
   if(errorMsg != "") {
     throw(new AssertError(errorMsg);
   }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.