zoukankan      html  css  js  c++  java
  • selenium webdriver 学习笔记(1)

    刚刚开通博客,记录一下学习历程和至今没有解决的问题。

    1.这是我开始学习selenium webdriver写的第一段代码

    package PRMselenium.pr;
    
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws Exception
        {
            
            WebDriver driver=new FirefoxDriver();
            driver.get("http://www.baidu.com/");
             System.out.println("第一个页面的标题是: " + driver.getTitle());
    
        }
    }

    然后就报错了

    2.发现是找不到Firefox的路径,下面是改进的代码

    package PRMselenium.pr;
    
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws Exception
        {
            System.setProperty("webdriver.firefox.bin", "D:\Program Files (x86)\Mozilla Firefox\firefox.exe");
            WebDriver driver=new FirefoxDriver();
            driver.get("http://www.baidu.com/");
             System.out.println("第一个页面的标题是: " + driver.getTitle());
    
        }
    }

    结果还是报错,我就去这个网站下载了一个geckodriver.exe,就是报错里面提示的网址https://github.com/mozilla/geckodriver/releases

    3.第二次修改之后的代码

    package PRMselenium.pr;
    
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws Exception
        {
            System.setProperty("webdriver.firefox.driver", "D:\Program Files (x86)\Mozilla Firefox\geckodriver.exe");
            System.setProperty("webdriver.firefox.bin", "D:\Program Files (x86)\Mozilla Firefox\firefox.exe");
            WebDriver driver=new FirefoxDriver();
            driver.get("http://www.baidu.com/");
             System.out.println("第一个页面的标题是: " + driver.getTitle());
    
        }
    }

    结果还是报错,然后我又换了好几个版本的geckodriver.exe,都没有用。到现在都没有解决,希望以后能找到原因。

    4.最后我感觉我还是换个浏览器吧,于是换上了ie浏览器

    package PRMselenium.pr;
    
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws Exception
        {
            WebDriver driver=new InternetExplorerDriver();
            driver.get("http://www.baidu.com/");
             System.out.println("第一个页面的标题是: " + driver.getTitle());
    
        }
    }

    结果报错了

    我去报错提示的地址下载了一个和我系统匹配的64位的IEDriverServer.exe,http://selenium-release.storage.googleapis.com/index.html

    5.修改之后的代码

    package PRMselenium.pr;
    
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws Exception
        {
            System.setProperty("webdriver.ie.driver","C:\Program Files (x86)\Internet Explorer\IEDriverServer.exe");
            WebDriver driver=new InternetExplorerDriver();
            driver.get("http://www.baidu.com/");
             System.out.println("第一个页面的标题是: " + driver.getTitle());
    
        }
    }

    运行之后,终于跑起来了(经历了一周的时间才跑起来第一个脚本)。

    在之后我发现64位的IEDriverServer会导致在win10上运行输入数字或者字母之类字符串的时候速度非常慢,经过百度查了下原因,换上了一个32位的IEDriverServer。

  • 相关阅读:
    Leetcode 15 3Sum
    Leetcode 383 Ransom Note
    用i个点组成高度为不超过j的二叉树的数量。
    配对问题 小于10 1.3.5
    字符矩阵的旋转 镜面对称 1.2.2
    字符串统计 连续的某个字符的数量 1.1.4
    USACO twofive 没理解
    1002 All Roads Lead to Rome
    USACO 5.5.1 求矩形并的周长
    USACO 5.5.2 字符串的最小表示法
  • 原文地址:https://www.cnblogs.com/7047-zfy/p/7364753.html
Copyright © 2011-2022 走看看