zoukankan      html  css  js  c++  java
  • selenium Java-1 配置

     

    1.使用intellij新建一个maven项目,名字自定。在pom中写入selenium的依赖。其他依赖也添加到该文件中。

    [maven selenium依赖](http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/3.12.0)

    [testNg依赖](http://mvnrepository.com/artifact/org.testng/testng/6.14.3)

     1 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
     2 <dependency>
     3     <groupId>org.seleniumhq.selenium</groupId>
     4     <artifactId>selenium-java</artifactId>
     5     <version>3.12.0</version>
     6 </dependency>
     7 
     8 
     9 <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    10 <dependency>
    11     <groupId>org.testng</groupId>
    12     <artifactId>testng</artifactId>
    13     <version>6.14.3</version>
    14     <scope>test</scope>
    15 </dependency>

    上述操作后,如果project报错,提示“the type's content type is element-only”,就将该行删除,重新输一次。

    2.如果下载过慢,就修改settings。intellij-preferances-maven-usersetting file-settings.xml。通过目录查找settings.xml

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name> 
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOF> </mirror>

     3.简单的用例

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import java.util.concurrent.TimeUnit;
    public class Baidu {
        public static void  main(String[] args){
         //设置Chromedriver的版本
    //System.setProperty("webdriver.chrome.driver","路径"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); driver.get("https://www.baidu.com"); driver.findElement(By.xpath("//input[@class='s_ipt' and @id='kw']")).sendKeys("selenium"); driver.findElement(By.xpath("//input[@id='su']")).click(); System.out.println(driver.findElement(By.xpath("//span[@class='nums_text']")).getText()); driver.quit(); } }

  • 相关阅读:
    第一篇:spring+springMVC项目启动最终笔记(一web.xml)
    Mysql优化系列之查询性能优化前篇1
    Mysql优化系列之索引性能
    java设计模式系列1-- 概述
    操作系统-死锁(重要)
    Mysql优化系列之表设计规范和优化
    Mysql优化系列之数据类型优化
    git-常见问题解决
    使用 jenkins 搭建CI/CD流水线 (MAC)
    jenkins 异常
  • 原文地址:https://www.cnblogs.com/csj2018/p/9185954.html
Copyright © 2011-2022 走看看