如何在硒中的“新建"选项卡中滚动 [英] How to scroll in New tab in selenium

查看:64
本文介绍了如何在硒中的“新建"选项卡中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过单击c#中硒中的某物打开了一个新标签.更改为新标签后,我想滚动,但是出现超时错误.

I opened a new tab by clicking something in selenium in c #. I want to scroll after changing to a new tab, but I get a timeout error.

我收到超时消息,没有滚动.

I get a timeout message and no scroll.

这是C#代码.

使用过的Chrome 79

Used Chrome 79

Chrome选项为

options.AddArguments("handlesAlerts=false");
            options.AddArguments("--disable-infobars");
            options.AddArguments("--no-sandbox");
            options.AddArguments("--disable-background-networking");
            options.AddArguments("--disable-component-extensions-with-background-pages");
            options.AddArguments("--dns-prefetch-disable");
            options.AddArguments("--ignore-certificate-errors");
            options.AddArguments("--ignore-certificate-errors-spki-list");
            options.AddArguments("--ignore-ssl-errors");
            options.AddArguments("--allow-running-insecure-content");
            options.AddArguments("lang=ko_KR");


if (this.driver.WindowHandles.Count > 1)
{
this.driver.SwitchTo().Window(this.driver.WindowHandles[1]);
}
Utils.sleep(3000);
((IJavaScriptExecutor)this.driver).ExecuteScript("window.scrollBy(0,500);");

推荐答案

您可以通过两个步骤完成此操作, 移至新的tab并在其中执行scroll.

you can do this by two steps, move to the new tab and do the scroll there.

ArrayList<String> AllTabs = new ArrayList<String> (driver.getWindowHandles()); 
driver.switchTo().window(AllTabs.get(1));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0 , window.innerHeight)");

您可以在完成操作后关闭该标签.

And you can close the tab after you finish.

这篇关于如何在硒中的“新建"选项卡中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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