zoukankan      html  css  js  c++  java
  • selenium-打开IE浏览器遇到问题记录

    【使用selenium打开IE浏览器步骤】:

      1、在IE浏览器上运行测试脚本,首先需要下载IEDriverServer.exe,放在IE浏览器的安装目录且同级目录下.

      2、参考代码如下:

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.WebDriverWait;import com.thoughtworks.selenium.webdriven.commands.WaitForCondition;
    
    public class SeleniumTest{
        private WebDriver driver;
        @Before
        public void setUp(){
            System.setProperty("webdriver.ie.driver", "C:\Program Files (x86)\Internet Explorer\IEDriverServer.exe");
            driver = new InternetExplorerDriver();
            System.out.println("打开浏览器");
        }
        
        @Test
        public void testLogic(){
            System.out.println("打开——>百度一下");
            driver.get("http://www.baidu.com/");
            WebDriverWait wait = new WebDriverWait(driver, 10);
            WebElement kw = wait.until(new ExpectedCondition<WebElement>() {
                public WebElement apply(WebDriver driver) {
                    return driver.findElement(By.id("kw"));
                }
            });
            try {
                if(kw!=null){
                    kw.sendKeys("selenium");
                    driver.findElement(By.id("su")).click();
                    Thread.sleep(1000);
                }
                System.out.println(driver.getCurrentUrl());
                
                Thread.sleep(10000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        
        @After
        public void tearDown(){
            if(driver!=null){
                driver.quit();
            }
        }
    }

    【遇到的问题及其解决方案】:

    1、报错:
    java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html 
    解决方法:
       设置 system propertySystem.setProperty("webdriver.ie.driver", "C:\Program Files (x86)\Internet Explorer\IEDriverServer.exe");
     
    2、报错:
    org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 1.15 seconds
    Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
    System info: host: 'PC-201wegfer', ip: '10.1.9.173', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: org.openqa.selenium.ie.InternetExplorerDriver
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     

    解决办法:

    IE安全保护都去掉: 
    internet选项——安全
    internet-启用保护模式 勾去掉 
    本地internet-启用保护模式 勾去掉 
    可信站点-启用保护模式 勾去掉

    除了上面的那几个,还需要在“受限制站点” 去除启用保护模式

  • 相关阅读:
    LightningChartJS2.0即将火热推出,敬请期待!
    html转word
    Windows上使用Python2.7安装pip
    人工智能?.netcore一样胜任!
    远程浏览服务器上的文件
    C# winform间窗体传值简单Demo
    C#发送QQ邮箱
    各种文件用JS转Base64之后的data类型
    当你的VS2019没法自动补全了,或者自动补全按回车直接换行的时候
    easyUI filebox 获取文件对象
  • 原文地址:https://www.cnblogs.com/splvxh/p/4218682.html
Copyright © 2011-2022 走看看