【使用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();
}
}
}
?
【遇到的問題及其解決方案】:
解決辦法:
IE安全保護都去掉:?
internet選項——安全
internet-啟用保護模式 勾去掉?
本地internet-啟用保護模式 勾去掉?
可信站點-啟用保護模式 勾去掉
除了上面的那幾個,還需要在“受限制站點” 去除啟用保護模式
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

