硒-具有透明代理的MoveToElement() [英] Selenium - MoveToElement() with transparent proxy

查看:134
本文介绍了硒-具有透明代理的MoveToElement()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有元素

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();

但是当我尝试运行它时,会出现错误

But when i try to run it, i will get error

'System.Reflection.TargetException'对象与目标类型不匹配.

'System.Reflection.TargetException' Object does not match target type.

我试图通过Browser.driver.FindElement(By.Id("someId"))定位此元素,然后它可以正常工作.因此,它存在并显示.
是否可以使用透明代理执行Actions?还有其他方法可以在透明代理上执行类似MoveToElement()的操作吗?

I tried to locate this element by Browser.driver.FindElement(By.Id("someId")) and then it is working correctly. So, it is present and displayed.
Is it possible to use transparent proxy to perform Actions? Is there any other way to perform MoveToElement() like action on transparent proxy?

推荐答案

要打开使用透明代理的元素,可以使用具有WrappedElement属性的IWrapsElement接口:

In order to unwrap element which using transparent proxy you can use IWrapsElement interface which has WrappedElement property:

action.MoveToElement(((IWrapsElement)btnTitleView).WrappedElement).Build().Perform();

您可能还希望将该演员表作为IWebElement对象的扩展方法:

You may also want to have that cast included as extension method of IWebElement object:

public static class IWebElementExtensions
{
    public static IWebElement Unwrap(this IWebElement element)
    {
        return ((IWrapsElement)element).WrappedElement;
    }
}

然后您的操作代码可能如下所示:

Then the code of your action might look like this:

Actions action = new Actions(Browser.driver);
action.MoveToElement(btnTitleView.Unwrap()).Build().Perform();

我希望答案会帮助您解决问题:)

I hope that answer will help you with your problem :)

这篇关于硒-具有透明代理的MoveToElement()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆