簡體   English   中英

切換窗口句柄並按Enter

[英]Switch windowHandles and press Enter

我想在所有選項卡之間切換,然后按Enter鍵。

web.SwitchTo().Window(web.WindowHandles[windowCounter]); javascript.ExecuteScript("$('button').click();");

在for循環中。 如果僅使用SwitchTo循環而不執行Javascript,則所有選項卡之間的切換需要7毫秒的時間。

當我使用js時,似乎正在等待完成文檔的加載。 我如何快速切換選項卡並按Enter即可不等待加載?

您需要將功能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();");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM