标签:
【使用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.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor; 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()); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("(function(){var q=document.documentElement.scrollTop=10000);})()"); Thread.sleep(10000000); } catch (InterruptedException e) { e.printStackTrace(); } } @After public void tearDown(){ if(driver!=null){ driver.quit(); } } }
【遇到的问题及其解决方案】:
解决办法:
IE安全保护都去掉:
internet选项——安全
internet-启用保护模式 勾去掉
本地internet-启用保护模式 勾去掉
可信站点-启用保护模式 勾去掉
除了上面的那几个,还需要在“受限制站点” 去除启用保护模式
标签:
原文地址:http://www.cnblogs.com/splvxh/p/4218682.html