Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C Selenium MoveByOffset引发InvalidOperationException_C#_Selenium - Fatal编程技术网

C# C Selenium MoveByOffset引发InvalidOperationException

C# C Selenium MoveByOffset引发InvalidOperationException,c#,selenium,C#,Selenium,我有以下Selenium C代码: IWebElement energyLink= driver.FindElement(By.LinkText("Energy")); Actions clickAction=new Actions(driver); clickAction.MoveToElement(energyLink).MoveByOffset(-25,0).Click().Build().Perform(); 单击Action.MoveToElementenergyLink.MoveB

我有以下Selenium C代码:

IWebElement energyLink= driver.FindElement(By.LinkText("Energy"));
Actions clickAction=new Actions(driver);
clickAction.MoveToElement(energyLink).MoveByOffset(-25,0).Click().Build().Perform();
单击Action.MoveToElementenergyLink.MoveByOffset-25,0.Click.Perform

我正在获取InvalidOperationException=参数“x”不是正整数IndexOutofBounds

我的目的是单击位于的第三方组件 X:15 Y:395

IWebElement energyLink位于坐标X:40,Y:395处


因此,我尝试使用MoveByOffset-25,0,我认为您是在Firefox上执行的

在selenium 2.53.1版本之后,它将使用geckodriver.exe在Firefox中执行自动化脚本

geckodriver中未实现Actions类。所以你得到了 这个错误

如果您在chrome中执行,那么您将不会得到该异常


如果您想在Firefox中执行,那么必须使用旧版本的selenium,它不需要geckodriver

ClickAndHOld:它用于左键单击特定元素并按住 MoveByOffset:将固定元素移动到给定位置 释放:在当前偏移位置释放图元 构建并执行:完成操作

    IWebElement energyLink= driver.FindElement(By.LinkText("Energy"));
    Actions clickAction=new Actions(driver);
    clickAction.ClickAndHold(energyLink).MoveByOffset(-25,0).Release().Build().Perform();

页面上的第三方组件不在元素中吗?用它作为参考,这样你就可以保持偏移量为正。嗨,阿米特,欢迎来到Stackoverflow,谢谢你分享你的解决方案,我只建议你描述一下这个解决方案是如何工作的,你做了什么不同的事情,以及为什么原始代码不能工作,如果可能的话