import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenWeb {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\admin\\Desktop\\chromedriver.exe");
System.setProperty("webdriver.chrome.bin", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com/");
driver.manage().window().maximize();
WebElement txtbox = driver.findElement(By.id("kw"));
txtbox.sendKeys("Glen");
WebElement btn = driver.findElement(By.id("su"));
btn.click();
Thread.sleep(3000);
driver.close();
driver.quit();
}
}
web ui自动化demo
最新推荐文章于 2023-07-17 11:21:29 发布
本文介绍如何使用Selenium WebDriver进行网页自动化测试,通过Java代码实现打开Chrome浏览器,访问百度首页并输入关键词进行搜索,最后关闭浏览器。示例代码详细展示了设置Chrome驱动路径、最大化窗口、定位搜索框及搜索按钮的过程。
902

被折叠的 条评论
为什么被折叠?



