1.根据谷歌版本下载chromedriver
http://chromedriver.storage.googleapis.com/index.html
2.IDEA新建maven项目
引入jar包:
maven仓库地址:https://mvnrepository.com/
搜索selenium-java、testng文章来源:https://www.toymoban.com/news/detail-429441.html
pom.xml加入:文章来源地址https://www.toymoban.com/news/detail-429441.html
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.4.0</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.6.1</version> <scope>test</scope> </dependency>
Test.java:
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test { public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "E:/javaSoft/selenium/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize();//全屏 driver.get("http://localhost:8080/XXX/");//打开网址 driver.findElement(By.name("username")).sendKeys("000231"); driver.findElement(By.name("password")).sendKeys("11"); Thread.sleep(1000); //driver.findElement(By.name("password")).sendKeys(Keys.ENTER);//通过Enter登录 driver.findElement(By.id("loginForm")).submit();//通过提交form表单登录 } }
到了这里,关于IDEA+Java+selenium+Testng安装配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!