有没有办法使用 Selenium 单击屏幕外的坐标?
我正在尝试使用硒在屏幕外的坐标点击。我发现的一切都滚动到元素/坐标。 但是,我无法滚动。该页面适合单个屏幕。
我已经尝试了以下内容,但是它给了我一个错误。
代码:
Actions a = new Actions(driver);
a.moveByOffset(10000, 10000).click().perform();
错误:
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)
在我的Main.java中40行(如错误所述)是:
a.moveByOffset(10000, 10000).click().perform();
非常感谢任何帮助
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如评论中所述,您无法单击视口。
但是,您可以修改浏览器大小以占据整个屏幕:
窗口也可以通过:
这扩展您可以单击的空间,并且(据我所知)由于硒的当前功能而成为最佳解决方案。
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:
The window can also be maximised by:
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.