Issue
I'm trying to click at coordinates off-screen using Selenium. Everything I've found has said to scroll to the element/coordinates. However, I cannot scroll. The page fits within a single screen.
I've tried the following, but it gives me an error.
Code:
Actions a = new Actions(driver);
a.moveByOffset(10000, 10000).click().perform();
Error:
Exception in thread "Thread-0" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move target out of bounds: viewport size: 1680, 896
(Session info: MicrosoftEdge=100.0.1185.29)
Build info: version: '4.0.0', revision: '3a21814679'
System info: host: 'DESKTOP-28HQ274', ip: '10.0.0.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: org.openqa.selenium.edge.EdgeDriver
Command: [1732248391f4756fc95c00a6d0f737c0, actions {actions=[org.openqa.selenium.interactions.Sequence@61904d24]}]
Capabilities {acceptInsecureCerts: false, browserName: msedge, browserVersion: 100.0.1185.29, javascriptEnabled: true, ms:edgeOptions: {debuggerAddress: localhost:54306}, msedge: {msedgedriverVersion: 100.0.1185.29 (1feddedadb21..., userDataDir: C:\Users\User\AppData\Local...}, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:54306/devtoo..., se:cdpVersion: 100.0.1185.29, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 1732248391f4756fc95c00a6d0f737c0
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:139)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:627)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:617)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:573)
at kingrabb.it.seleniumtest.Main.lambda$new$0(Main.java:40)
at java.base/java.lang.Thread.run(Thread.java:831)
Line 40 in my Main.java (as mentioned in the error) is:
a.moveByOffset(10000, 10000).click().perform();
Any help is greatly appreciated
Solution
As stated in the comments, you cannot click out of the viewport.
However, you can modify the browser size to take up your entire screen:
driver.manage().window().setSize(new Dimension(1680, 896));
The window can also be maximised by:
driver.manage().window().maximize();
This expands the space that you can click and is (as far as I'm aware) the best solution due to Selenium's current capabilities.
Answered By - KingsMMA
Answer Checked By - Gilberto Lyons (JavaFixing Admin)