selenium简单使用
selenium一般用来做web页面的自动化,selenium的底层是webDriver,首先要下载jdk,配置环境,要下载selenium的jar包,
然后使用idea,到idea里面安装testNg jar包,代码如下
public class AutoTest { //百度搜索脚本,找到搜索框,输入iPhone11,点击搜索 @Test public static void test() throws InterruptedException { //导入selenium jar包 System.setProperty("webdriver.chrome.driver","D:\\AutoScript\\selenium-server-standalone-2.45.0.jar"); WebDriver dr = new ChromeDriver(); dr.get("https://www.baidu.com"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //找到搜索框,输入iPhone11,点击搜索 dr.findElement(By.id("kw")).sendKeys("iphone 11"); Thread.sleep(1000); dr.findElement(By.id("su")).click(); Thread.sleep(1000); dr.quit(); } }