我要在所有选项卡之间切换,然后按ENTER键。
web.SwitchTo().Window(web.WindowHandles[windowCounter]); javascript.ExecuteScript("$('button').click();");
在for循环中。如果我只使用SwitchTo循环,而不执行Javascript,那么在所有选项卡之间切换需要7毫秒。
当我使用js时,它似乎在等待完成文档的加载。如何在不等待加载的情况下快速切换选项卡并按enter键切换到所有选项卡?
发布于 2017-08-09 22:02:39
您需要将capability pageLoadStrategy设置为none。然而,ChromeDriver似乎并不支持DesiredCapability。您可能需要一种解决方法。下面的示例使用RemoteWebDriver来设置DesiredCapability。它将打开一个空白的Chrome,然后第一次关闭它。
string binLocation = @"./";
ChromeOptions chromeOpt = new ChromeOptions();
chromeOpt.AddArguments("--disable-extensions");
ChromeDriverService service = ChromeDriverService.CreateDefaultService(binLocation);
service.Port = 9515;
var driver = new ChromeDriver(service, chromeOpt);
driver.Close();
var options = new Dictionary<string, object>();
options.Add("browserName", "chrome");
options.Add("pageLoadStrategy", "none");
var capabilities = new DesiredCapabilities(options);
var driver = new RemoteWebDriver(new Uri("http://localhost:9515"), capabilities);
// do your works here //
////////////////////////
web.SwitchTo().Window(web.WindowHandles[windowCounter]);
// Make sure the button is clickable. You may use WebDriverWait.
javascript.ExecuteScript("$('button').click();");https://stackoverflow.com/questions/45578266
复制相似问题