美文网首页selenium
让自己的selenium程序成功的自动打开网页-问题记录

让自己的selenium程序成功的自动打开网页-问题记录

作者: 流浪骑士 | 来源:发表于2015-12-15 17:14 被阅读1399次

第一次执行:

package mycss;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Test1 {

    public static void main(String[] args) {
        
        WebDriver driver = new InternetExplorerDriver();
        driver.get("www.baidu.com");

    }
}

报错如图:


Paste_Image.png

下载IEDriverServer.exe并放在代码工程路径下面,然后修改代码继续运行:

package mycss;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Test1 {

    public static void main(String[] args) {
        
        
        String IEPath = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
        String pro_Path = System.getProperty("user.dir");
        String IEDriver_Path = pro_Path + "\\IEDriverServer.exe";
        
        System.setProperty("webdriver.ie.bin", IEPath);
        System.setProperty("webdriver.ie.driver", IEDriver_Path);
        
        WebDriver driver = new InternetExplorerDriver();
        driver.get("www.baidu.com");
        
    }
}

运行后又报错:

Paste_Image.png

再次修改:

package mycss;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Test1 {

    public static void main(String[] args) {
        
        //ie浏览器路径
        String IEPath = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
        String pro_Path = System.getProperty("user.dir");
        //打开ie浏览器的driver
        String IEDriver_Path = pro_Path + "\\IEDriverServer.exe";
        
        System.setProperty("webdriver.ie.bin", IEPath);
        System.setProperty("webdriver.ie.driver", IEDriver_Path);
        
        //设置IE安全机制
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        WebDriver driver = new InternetExplorerDriver(ieCapabilities);
        driver.get("www.baidu.com");
        
    }
}

这次终于打开IE浏览器了。

相关文章

网友评论

    本文标题:让自己的selenium程序成功的自动打开网页-问题记录

    本文链接:https://www.haomeiwen.com/subject/iqbuhttx.html