selenium调用IE11和Firefox浏览器

版权声明:本文为博主原创,若转载请附上博文链接 https://blog.csdn.net/liudong124521/article/details/89453416

selenium调用IE浏览器与调用chrome方法相同,但是需要对IE做出一些设置

1、将此四处的保护模式关掉:
在这里插入图片描述


2、将增强保护模式关掉:
在这里插入图片描述


3、若浏览器版本为IE11,还需要修改注册表
路径为
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
若路径下FEATURE_BFCACHE不存在,就新建一个项,然后右键此项新建如下内容:
在这里插入图片描述


selenium调用IE11的类如下,同样是一个打开网页获取并输出标题的简单操作:

import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;

   public class IeTest {
   WebDriver driver;
   @BeforeTest
   public void beforeMethod() {
       System.setProperty("webdriver.ie.driver","driver\\IEDriverServer.exe");
       driver = new InternetExplorerDriver();//初始化driver
       driver.manage().window().maximize();
   }

   @AfterMethod
   public void afterMethod() {
       System.out.println("Page title is: " + driver.getTitle());
       driver.quit();
   }

   @Test
   public void test_case3() {
       driver.get("http://www.baidu.com");
   }
}


Firefox

selenium调用Firefox浏览器与调用chrome方法相同,以下是特殊情况处理
如遇到此类报错
Exception in thread “main” org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.
原因是无法找到Firefox浏览器,解决方法有两个
1、卸载Firefox,重新安装到默认路径
2、在WebDriver driver = new FirefoxDriver(); 前面指定Firefox具体信息(此方法未经过验证):

System.setProperty("webdriver.firefox.bin","D:\\Firefox\\firefox.exe");

猜你喜欢

转载自blog.csdn.net/liudong124521/article/details/89453416