Selenium 如何制作点击并按住按钮

szp*_*pic 3 selenium automated-tests

在网页中,我测试的是一个模态,它在按下按钮约 5 秒后出现。

现在我试图在selenium. 我有这样的方法:

public static void ClickHold(IWebElement by)
{
    SpecialInteractions.ClickAndHold(by);
}
Run Code Online (Sandbox Code Playgroud)

在哪里

public static Actions SpecialInteractions { get; set; }
Run Code Online (Sandbox Code Playgroud)

并且没有要设置的保持时间。

看起来就像只是点击和释放。有没有办法等待特定的时间然后释放?

Sai*_*fur 5

不挖北斗我可以告诉你上面的程序可能会返回NulReference exception。我怀疑您需要Actions通过包装当前驱动程序实例来实例化。

可能的解决方案可能是:

public void ClickHold(IWebElement element)
{
    Actions action = new Actions(driver);
    action.clickAndHold(webelement).build().perform();
    //you need to release the control from the test
    //actions.MoveToElement(element).Release();
}
Run Code Online (Sandbox Code Playgroud)