Selenium+Java Web自動化テスト環境の構成
公式構成リファレンス:https://www.selenium.dev/documentation/en/selenium_installation/installing_selenium_libraries/
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
</dependency>
の他のブラウザを導入します.例えば火狐<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.X</version>
</dependency>
下図参照のブラウザドライバは、サポートされているブラウザchrome、edge、firefox...
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
</dependency>
export PATH="$PATH:/path/to/chromedriver"説明:/path/to/chromedriverを自分のアドレスに変更
次の図のように正常に動作

public class Test {
public static void main(String[] args) {
// chromedriver ,/path/to/chromedriver chromedriver
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
// ChromeDriver
WebDriver driver = new ChromeDriver();
String url = "http://www.baidu.com";
//
driver.get(url);
//
// accout
driver.findElement(By.id("account")).sendKeys("accout");
// 111111
driver.findElement(By.id("password")).sendKeys("111111");
//
WebElement login = driver.findElement(By.className("antd-pro-components-login-index-submit"));
//
login.click();
}
}
実行すると、ブラウザで