How to get the WebElement in ITestListener class on TestFailure Method. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to get the WebElement in ITestListener class on TestFailure Method.

I want to get the WebElement in ITestListener class on TestFailure Method. Is there any way to get the WebElement in ItestListener on testfailure method? I have tried to get the testclass name and testmethodname and it worked but how to get WebElement: // WebElement inputbox i need this in ItestListener public void test1() { String title = driver.getTitle(); String etitle = "Google1"; WebElement inputbox = driver.findElement(By.id("fakebox-input1")); inputbox.click(); Assert.assertEquals(title, etitle); } // my Listener class public void onTestFailure(ITestResult iTestResult) { System.out.println("Test failed >......."); String classname = iTestResult.getInstanceName(); // class name this.driver = demo.driver; System.out.println(iTestResult.getName()); // test method name CaptureScreenShot cs = new CaptureScreenShot(); cs.takescreenshotoferror(iTestResult.getName(), driver); } I can get the class name and method name on testfailure, using this: get

30th Jun 2019, 11:06 AM
vinay shetty
vinay shetty - avatar
1 Answer