The ultimate goal is to get the WebElement variable name for reporting purposes.
The below is the code I have.
Class A:
Class A{
public void Click(WebElement element)
{
element.click();
System.out.println("Clicked on"+ element);
}
}
Class B:
class B extends A{
@FindBy(xpath = "//li[@class='login-menu']//a[text()='Log In']")
WebElement link_Log_In;
Click(link_Log_In);
}
Desired Output:
Clicked on link_Log_In
Actual Output:
Clicked on[[ChromeDriver: chrome on XP (acc46d4d382511d7b18396d4a4dddd30)] -> xpath: //li[@class='login-menu']//a[text()='Log In']]
Also I would like to print the same Desired Output in extent report using afterClickOn(WebElement element, WebDriver driver) method in WebDriverEventListener.
I have created the framework in such a way that WebDriverEventListener results are printed in Extent Reports as required but however unable to print Desired Output as stated above.
Please advise if i'm missing something in the above code and to achieve the same in afterClickOn(WebElement element, WebDriver driver) method in WebDriverEventListener
Below is the event listener afterClickmethod
public void afterClickOn(WebElement element, WebDriver driver) {
System.out.println("Clicked On"+element); // this is to print in console
ExtentManager.getTest().log(Status.valueOf(element), "clicked on"); // this is to print in extent report
}