System.setProperty("webdriver.edge.driver", "C:\\Users\\xxxx\\eclipseworkspace\\selenium\\msedgedriver.exe");
WebDriver driver = new EdgeDriver();
driver.get("https://www.selenium.dev/documentation/webdriver/interactions/alerts");
WebElement Okcancel = driver.findElement(By.xpath("/html/body/div/div[1]/div/main/div/p[5]/a"));
Okcancel.click();
The above code snippet where issue is exists.
Website Link : https://www.selenium.dev/documentation/webdriver/interactions/alerts/
ERROR MSG:
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:134)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:51)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:519)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:223)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:76)
at selenium.PopUp.main(PopUp.java:27)
I need a solution, for this what needs to be done to resolve this error.
The link which you are trying to click is not displayed fully in the current context of the screen. So you can try to click on the link in multiple ways as below.
By using the Actions class
By using JavascriptExecutor
By Using ChromeOptions/EdgeOptions you can zoom out the screen so that the link gets displayed