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。

 

转载于:https://www.cnblogs.com/7047-zfy/p/7364753.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值