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

第一次执行:

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浏览器了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,856评论 25 709
  • 从三月份找实习到现在,面了一些公司,挂了不少,但最终还是拿到小米、百度、阿里、京东、新浪、CVTE、乐视家的研发岗...
    时芥蓝阅读 42,473评论 11 349
  • 这个雷电风雨交加的季节,给人的感觉非常的缺乏安全感。 不禁心生恐惧,迷茫,失意,失落感。曾经的一切美好的梦想也好,...
    偶像团长阅读 3,192评论 0 11
  • 终于结束了3忙时段,感觉这段时间很有意义,让我懂得了“成长”的含义: 不管你是成功还是失败,现实就是现实,你只能选...
    龙少么么哒阅读 1,313评论 3 0