我有元素
public ArticlePage()
{
PageFactory.InitElements(browser.driver, this)
}
[FindsBy(How = How.Id, Using = "someId")]
private IWebElement btnTitleView { get; set; }
和行动
Actions action = new Actions(browser.driver);
action.MovetoElement(btnTitleView).Perform();
但是当我尝试运行它时,我会收到错误消息
‘System.Reflection.TargetException’ Object does not match target type.
我试图通过browser.driver.FindElement(By.Id(“ someId”))找到此元素,然后它可以正常工作.因此,它存在并显示.
是否可以使用透明代理执行操作?还有其他方法可以对透明代理执行类似MovetoElement()的操作吗?
解决方法:
为了解开使用透明代理的元素,您可以使用具有WrappedElement属性的IWrapsElement接口:
action.MovetoElement(((IWrapsElement)btnTitleView).WrappedElement).Build().Perform();
您可能还希望将该强制转换作为IWebElement对象的扩展方法包括在内:
public static class IWebElementExtensions
{
public static IWebElement Unwrap(this IWebElement element)
{
return ((IWrapsElement)element).WrappedElement;
}
}
然后,您的操作代码可能如下所示:
Actions action = new Actions(browser.driver);
action.MovetoElement(btnTitleView.Unwrap()).Build().Perform();
我希望答案能帮助您解决问题:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。