using System;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
namespace IEDriverSample
{
class Program
{
static void Main(string[] args)
{
var ieOptions = new InternetExplorerOptions();
ieOptions.AttachToEdgeChrome = true;
//change the path accordingly
ieOptions.EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
var driver = new InternetExplorerDriver(ieOptions);
driver.Url = "https://bing.com";
driver.FindElement(By.Id("sb_form_q")).SendKeys("WebDriver");
driver.FindElement(By.Id("sb_form")).Submit();
driver.Quit();
}
}
}
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
ie_options = webdriver.IeOptions()
ie_options.attach_to_edge_chrome = True
ie_options.edge_executable_path = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
driver = webdriver.Ie(options=ie_options)
driver.get("http://www.bing.com")
elem = driver.find_element(By.ID, 'sb_form_q')
elem.send_keys('WebDriver' + Keys.RETURN)
driver.quit()
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
public class IEDriverSample {
public static void main(String[] args) {
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
driver.get("http://www.bing.com");
WebElement elem = driver.findElement(By.id("sb_form_q"));
elem.sendKeys("WebDriver", Keys.RETURN);
driver.close();
}
}
var initialHandleCount = driver.WindowHandles.Count;
driver.FindElement(By.Id("<Id of the button that will open a new window>")).Click();
var newHandles = driver.WindowHandles;
while (newHandles.Count == initialHandleCount)
{
newHandles = driver.WindowHandles;
}
initial_handle_count = len(driver.window_handles)
driver.find_element(By.ID, "<Id of the button that will open a new window>").click()
new_handles = driver.window_handles
while len(new_handles) == initial_handle_count:
new_handles = driver.window_handles
int initialHandleCount = driver.getWindowHandles().size();
driver.findElement(By.id("<Id of the button that will open a new window>")).click();
Set<String> newHandles = driver.getWindowHandles();
while (newHandles.size() == initialHandleCount) {
newHandles = driver.getWindowHandles();
}
const initialHandleCount = (await driver.getAllWindowHandles()).length;
const elem = await driver.findElement(By.id("<Id of the button that will open a new window>"));
await elem.click();
let newHandles = await driver.getAllWindowHandles();
while (newHandles.length == initialHandleCount) {
newHandles = await driver.getAllWindowHandles();
}
创建选项卡并在选项卡之间切换
如果测试代码在同一Microsoft Edge 窗口中的多个选项卡之间切换,则变为非活动的选项卡可能不会包含在 “获取窗口句柄”返回的句柄列表中。 在 Internet Explorer 11 桌面应用程序中,无论激活状态如何,IEDriver 都将返回 IE 中所有选项卡的句柄。
在 IE 模式下使用 Microsoft Edge 时,如果测试将焦点从某个选项卡移开,并且你希望以后能够切换回该选项卡,则必须存储选项卡窗口句柄的副本。