i want to press a key with JavascriptExecutor.For this I have created a class and a static method.
private static JavascriptExecutor jsExecutor = (JavascriptExecutor)BrowserFactory.getDriver();
public static void clickButton(BaseElement element){
jsExecutor.executeScript("arguments[0].click()", element.getLocator());
}
But when in my PageObject method I call the button click, I get an error
public void clickForJsAlertButton() {
ScriptManager.clickButton(elementButton);
}
java.lang.IllegalArgumentException: Argument is of an illegal type: org.openqa.selenium.By$ByXPath
I do not understand why this is happening and what needs to be done to fix it
jsExecutor - only works with WebElement
public static void clickButton(By locator){
WebElement element = BrowserFactory.getDriver().findElement(locator);
jsExecutor.executeScript("arguments[0].click()", element);
}