TA的每日心情 | 擦汗 2024-11-1 14:56 |
---|
签到天数: 1182 天 连续签到: 1 天 [LV.10]测试总司令
|
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- public class baiDuTest {
- public static void main(String args[]){
- String path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe";
- //设置浏览器的路径
- System.setProperty("webdriver.chrome.driver",path);
- WebDriver driver = new ChromeDriver();
- driver.get("http://www.baidu.com");
- //窗口最大化
- driver.manage().window().maximize();
- System.out.println("网页Title:"+driver.getTitle());
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- WebElement we = driver.findElement(By.id("kw"));
- // we.clear();
- we.sendKeys("selenium");
- // WebElement btn = driver.findElement(By.id("su"));
- // btn.click();
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("网页Title:"+driver.getTitle());
- driver.quit();
- }
- }
复制代码 |
|