1.selenium中啟動ie瀏覽器代時碼(紅框中)如下 :
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名與空間、虛擬空間、營銷軟件、網站建設、五通橋網站維護、網站推廣。
點擊運行時,控制臺報錯如下:
Started InternetExplorerDriver server (64-bit)
2.53.0.0
Listening on port 31574
Only local connections are allowed
Exception in thread "main" 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: 692 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'XL-20150414QGDQ', ip: '192.168.80.6', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_80'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:234)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)
at org.openqa.selenium.ie.InternetExplorerDriver.
at org.openqa.selenium.ie.InternetExplorerDriver.
at Project1Class.main(Project1Class.java:13)
解決方法:
解決方法有兩種,一種是修改掉IE的設置,不要在任何情況下使用保護模式(protected mode),另一種即是在前面代碼中如下片段在運行時設置IE的Capabilities。
添加后代碼如下:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
提示錯誤信息可參考如下地址:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver.
The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
2.關于下拉框的定位法 :
方法一:如果該下拉框是html原生的select ,則可用selenium的select方法定位; 但是如果是自己開發(fā)的下拉框,則不能用該方法。
Select selectCategory1 = new Select(driver.findElement(By.id("category_1")));
selectCategory1.selectByVisibleText("java");
Select selectCategory2 = new Select(driver.findElement(By.id("category_2")));
selectCategory2.selectByVisibleText("3D游戲");
Select selectCategory3 = new Select(driver.findElement(By.id("difficulty")));
selectCategory3.selectByVisibleText("中級");
否則將會報如下錯誤:
3.關于編輯器中文本框的定位問題,在里,但找不到任何可定位的元素,待解決。