package com.walker.web.driver; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; public class TestChrome { public static WebDriver driver; @BeforeAll public static void SetUp() { System.setProperty("webdriver.chrome.driver","D:/dev_tools/chromedriver_105.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--start-maximized"); // options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation")); // options.setExperimentalOption("useAutomationExtension",false); driver = new ChromeDriver(options); } @Test public void LoginTest() { driver.get("https://www.baidu.com/?tn=62095104_26_oem_dg"); // 1:找到登录按钮,点击 new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.id("s-top-loginbtn"))).click(); System.out.println("等待3秒"); // driver.findElement(By.name("tj_login")).click(); // 2:输入登录信息 // 等待元素可以点击 new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.id("TANGRAM__PSP_11__userName"))); driver.findElement(By.id("TANGRAM__PSP_11__userName")).sendKeys("pxzsky@163.com"); driver.findElement(By.id("TANGRAM__PSP_11__password")).sendKeys("Pxzsky@837589"); driver.findElement(By.id("TANGRAM__PSP_11__submit")).click(); } // @AfterAll public static void TearDown(){ driver.quit(); } }