IE自动化下的Exception
IE 自动化下Exception
1.Protected Mode Setting are not same for all zones.
1.浏览器设置,但是换了电脑就不能使用了
IE浏览器安全模式设置,取消勾选
2.代码解决以上问题,这样不论在那台电脑,都可以正常运行
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURIY_DOMAINS
代码:
DesiredCapabilities capabilities=new DesiredCapablities();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURIY_DOMAINS,true)
2.遇到浏览器页面最大化
3.缺少IE浏览器驱动包
解决方法:往项目中添加IE驱动包,并加载驱动配置
System.setProperty("webdriver.ie.driver","src/test/resources/IEDriverServer.exe");
有时候配置完不生效就project->Clean
public void IEBrowser() {
//1.驱动文件找不到异常
System.setProperty("webdriver.ie.driver","src/test/resources/IEDriverServer.exe");
//创建一个设置对象,用来设置创建IE驱动时的各种设置
DesiredCapabilities capabilities=new DesiredCapabilities();
//2.取消IE安全设置,忽略IE的protected Mode的设置
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURIY_DOMAINS,true);
//3.忽略浏览器的页面缩放设置
capabilities.setCapability(INTERNETEXPLORERDRIVER.IGNORE_ZOOM_SETTING,True);
import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class IEtestforDesiredCapabilities { public static void main(String[] args) { //it is used to define IE capability DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE"); capabilities.setCapability(InternetExplorerDriver. INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe"); //it is used to initialize the IE driver WebDriver driver = new InternetExplorerDriver(capabilities); driver.manage().window().maximize(); driver.get("http://gmail.com"); driver.quit(); } }