shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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();
    }
}