您可以从以下文件夹中找到 Microsoft Edge WebDriver:
C:\\Windows\\WinSxS\\amd64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_c52dd23839475f5b\\MicrosoftWebDriver.exe
C:\\Windows\\System32\\MicrosoftWebDriver.exe
C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe
C:\\Windows\\WinSxS\\wow64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_cf827c8a6da82156\\MicrosoftWebDriver.exe
然后,参考以下代码将 Microsoft Edge WebDriver 与 Java 结合使用:
package seleniumtest;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class testsample {
public static void main(String[] args) {
//String windir = System.getenv("windir");
//String edgeDriverPath = windir + "\\SysWOW64\\MicrosoftWebDriver.exe";
//String edgeDriverPath = "C:\\Windows\\WinSxS\\amd64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_c52dd23839475f5b\\MicrosoftWebDriver.exe";
//String edgeDriverPath = "C:\\Windows\\System32\\MicrosoftWebDriver.exe";
//String edgeDriverPath = "C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe";
String edgeDriverPath = "C:\\Windows\\WinSxS\\wow64_microsoft-webdriver-server-components_31bf3856ad364e35_10.0.18362.1_none_cf827c8a6da82156\\MicrosoftWebDriver.exe";
System.setProperty("webdriver.edge.driver", edgeDriverPath);
WebDriver driver = new EdgeDriver();
//replace the URL of the web page here..
driver.get("https://www.bing.com");
//wait page load success.
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sb_form_q")));
//find the element from the web page.
WebElement element = driver.findElement(By.id("sb_form_q"));
//enter value and search
element.sendKeys("web driver");
element.sendKeys(Keys.ENTER);
}
}