zoukankan      html  css  js  c++  java
  • 1.selenium+java+maven+testNg 的安装

    1.搭建环境之前,要先安装java的jdk、idea工具,请自行安装

    ①Java运行环境–jdk

    https://www.oracle.com/java/technologies/javase-jdk11-downloads.html

    ②IDE–idea
    https://www.jetbrains.com/idea/download/#section=mac

    ③下载chrom对应的chromdriver,先看自己的浏览器的版本,再去下载对应的chromdriver,不然程序会报错

    https://chromedriver.storage.googleapis.com/index.html

    下载后得到的文件,在访达中打开,把下载好的文件拖动到 /usr/local/bin目录下

    打开/usr/local/bin的方法
        1 打开mac自带命令行,输入:cd /usr/local/bin
        2 再输入:open .则成功打开此目录

    这时chromdriver就配置好了,可以打开命令行输入chromedriver --version来看,能返回具体的版本号则表示安装成功~

    2.在idea里面新建一个maven项目,然后在pom.xml里面需要引入几个依赖包。

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>

    3. 运行一个例子

    import org.openqa.selenium.By;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    
    public class Test {
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");//这里输入chromedriver的安装目录
            ChromeDriver driver = new ChromeDriver();
            driver.get("https://www.baidu.com/");
            driver.findElement(By.name("wd")).click();
            driver.findElement(By.name("wd")).sendKeys("selenium教程" );
            driver.findElement(By.id("su")).click();
            try {
                Thread.sleep(2000);
            }catch(InterruptedException e){
                System.out.print("线程异常");
            }
            
            driver.quit();
        }
    }
  • 相关阅读:
    70. Climbing Stairs(动态规划)
    53. Maximum Subarray(动态规划)
    PAT 1045. Favorite Color Stripe
    PAT 1044. Shopping in Mars
    分治策略
    时间复杂度和空间复杂度分析(转载)
    [转载]论坛中某位达人自己编写的Morlet连续小波变换程序
    连续小波时频图绘制原理    连续小波变换尺度与信号频率的关系
    Matlab中wavedec使用學習及詳解
    [转载]转载:小波分解层数与尺度的关系
  • 原文地址:https://www.cnblogs.com/peiminer/p/13554935.html
Copyright © 2011-2022 走看看