-4

Am working on selenium Automation

I want to know the name of which elements is not found when test cases got failed instead of getting object not found with property By.id("Login")

am expecting output like Object not found LoginButton(Customized name which i will give in code) when test cases fails due to defect

public static void logonCustomerPortal() throws Exception{
    Thread.sleep(5000);
    driver.findElement(By.xpath("//a[@id='nav_login']/span")).click();
    Thread.sleep(2000);
}

I am new to Automation. Can anyone please help me ?

  • Possible duplicate of [How can I ask the Selenium-WebDriver to wait for few seconds in Java?](http://stackoverflow.com/questions/12858972/how-can-i-ask-the-selenium-webdriver-to-wait-for-few-seconds-in-java) – Jason D Dec 22 '15 at 14:57
  • This can be achieved by using Try Catch in Java. You can catch the exception and you can then do whatever you want to do in the catch block. – Paras Dec 22 '15 at 15:04
  • In try block if I have more they one findElement statements and then if second or third fails how can I handle in catch block to customized output like login button got failed instead of xyz property got failed – Santhosh Chandrashekar Dec 22 '15 at 16:41
  • Make the try-catch tighter. – qqilihq Dec 23 '15 at 09:01

1 Answers1

0

try to use try catch like this :

public void urmethod(){
    try {
         //do your code
    }catch (Exception e){
         e.printStackTrace();
   }
}

this will print details of your error, in other words, what kind of error, in which line it fails...etc

noor
  • 2,954
  • 2
  • 16
  • 29