java - WebElementProxy 应该实现什么才能将其传递给 Actions.moveToElement(WebElement)?
问题描述
里面有org.openqa.selenium.interactions.Actions
一个名为的方法moveToElement(WebElement target);
我有一个类WebElementProxy
,它实现WebElement
:
public class WebElementProxy implements WebElement {
private WebElement el;
public WebElementProxy(WebElement el) {
this.el = el;
}
/* Implement methods from WebElement, delegating directly to el field. */
}
当我尝试打电话时,new Actions(driver).moveToElement(webElementProxy)
我收到以下错误:
class mypackage$WebElementProxy cannot be cast to class org.openqa.selenium.interactions.Locatable
因此,我在 WebElementProxy 的接口中添加了 Locatable:
public class WebElementProxy implements WebElement, Locatable {
private WebElement el;
public WebElementProxy(WebElement el) {
this.el = el;
}
/* Implement methods from WebElement and Locatable, delegating directly to el field. */
}
现在,当我打电话时,new Actions(driver).moveToElement(webElementProxy)
我收到以下错误:
invalid argument
from invalid argument: 'origin' must be either a string or a dictionary
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:618)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:639)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:595)
at the place in my project where I called actions.movetoElement()
在这一点上,我不知道我还需要实现什么才能使这个方法调用正常工作。我在这里想念什么?
解决方案
在类似的情况下(使用 Serenity 的 WebElementFacade),它通过直接传递底层元素为我解决了:new Actions(driver).moveToElement(el)
.
推荐阅读
- powerbi - 报表不显示 Power BI 上的刷新数据 - SSAS 表格模型
- html - Angular 11 不应用具有不同状态的多个转换
- vba - 如何从 Microsoft Word for Mac 版本 16 中的剪贴板获取文本?
- python - 有没有办法使用 Python 乌龟旋转整个画布?
- python - 按下内联按钮后显示内联键盘
- azure-data-factory - 为什么 Azure 数据工厂使用 AppendFile 而不是 PutBlob 将文件写入 Blob 存储容器?
- spring-batch - 从 Spring 批处理分区工作步骤存储作业级别数据的最佳方法是什么?
- scala - 是什么导致该类型与 Scala 中的基础类型不匹配
- macos - 是什么导致 SwiftUI 的 Picker 在 macOS 上吞星?
- react-native - React Naitve i18n ,如何翻译 useState() 的内容?