简体   繁体   English

无法使用 selenium 向下滚动页面 - nUnit,C#

[英]Not able scroll down the page using selenium - nUnit, C#

I am getting the following error while trying to click on a button which is present at the bottom of the page.尝试单击页面底部的按钮时出现以下错误。 Looks like this error is coming because that button is not visible at the first point, if we scroll the page down then only selenium is able to identify that button.看起来出现此错误是因为该按钮在第一点不可见,如果我们向下滚动页面,则只有 selenium 能够识别该按钮。

OpenQA.Selenium.ElementClickInterceptedException : element click intercepted: Element <span>...</span> is not clickable at point (1113, 659)..

I have tried with following code to scroll down the web page but it does not help me.我尝试使用以下代码向下滚动 web 页面,但它对我没有帮助。

Actions actions = new Actions(driver);
actions.SendKeys(Keys.ArrowDown);

If I try with element.Sendkeys(Keys.ArrowDown) then also its not helping.如果我尝试使用element.Sendkeys(Keys.ArrowDown)那么它也没有帮助。

what would be the correct approach here?这里正确的方法是什么?

You should use Actions class to perform scrolling to the element in this way您应该使用Actions class 以这种方式执行滚动到元素

Actions actions = new Actions(driver);
var element = driver.FindElement(...);
actions.MoveToElement(element);
actions.Perform();

substitute ... with the selector for the element....替换为元素的选择器。

There is also another method relying on javascript还有一种方法依赖javascript

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM