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# Can';不移动到webelement?_C#_Selenium_Selenium Webdriver - Fatal编程技术网

C# Can';不移动到webelement?

C# Can';不移动到webelement?,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,显然,selenium在视图中之前不会与webelement交互,并且selenium会自动尝试滚动到该webelement。但在我的例子中,当我尝试单击某个特定按钮时,它不会滚动到视图中,它只是滚动到页面中的一个随机位置 目标: 将webelement滚动到视图中,然后单击该元素 我已经使用过的方法: element.Click(); //method 1 Actions actions = new Actions(driver); // method 2 actions.MoveToEle

显然,selenium在视图中之前不会与webelement交互,并且selenium会自动尝试滚动到该webelement。但在我的例子中,当我尝试单击某个特定按钮时,它不会滚动到视图中,它只是滚动到页面中的一个随机位置

目标: 将webelement滚动到视图中,然后单击该元素

我已经使用过的方法:

element.Click(); //method 1

Actions actions = new Actions(driver); // method 2
actions.MoveToElement(element);
actions.Perform();

IJavaScriptExecutor js = driver as IJavaScriptExecutor; //method 3
js.ExecuteScript("$('#Id_Body' + element_id)[0].scrollIntoView( true );"); //because the driver scrolls to a random place I use this to get back to the top of the page.
int Y = element.Location.Y, X = element.Location.X;
js.ExecuteScrip($"window.scrollBy( {X}, {Y};");
我使用的是selenium 2.48.0和firefoxDriver 43.0.1

这个问题有解决方案吗?如果有人知道旧版本的selenium/firefox可以使用这些方法之一,请告诉我,谢谢

为什么不直接使用:

js.ExecuteScript("arguments[0].scrollIntoView();", element); 

请尝试双击
MoveToElement

Actions action = new Actions(driver);
action.MoveToElement(elementParent).MoveToElement(elementToClick).Build().Perform();
首先移动到图元区域,然后移动到要单击的图元