【Selenium-WebDriver自學】出現的問題和解決方案(十七)

 

 

==========================================================================================================javascript

 

    寫在前面:css

 

    從開始學習Selenium和Webdriver開始,就會遇到各類問題,遇到問題就解決問題,因此這一個階段也是不斷的完善過程當中。html

 

==========================================================================================================java

 

 

1. 報錯:
org.openqa.selenium.firefox.NotConnectedException

緣由:
FireFox和Selenium的版本不匹配致使
webdriver啓動firefox時若是遇到如下錯誤,則說明selenium的版本和firefox不兼容了,須要升級selenium:
Selenium ->FireFox
2.25.0 -> 18
2.30.0 ->19
2.31.0 ->20
升級selenium jar包
正常啓動firefox
http://blog.csdn.net/sinat_29741049/article/details/57405191
http://ftp.mozilla.org/pub/firefox/releases/

證實:
2.52.0->43.0Firefox
能夠正常啓動

2.alert處理
http://www.cnblogs.com/qiaoyeye/p/5593428.html

[org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : 確認刪除此客戶嗎?}
(Session info: chrome=59.0.3071.104)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds: null
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'WIN-UBMLJ97RGF8', ip: '172.16.0.108', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir16596_23783}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.104, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 5228d8eb9d66ab2a0d06aa25837dabb2]

3.@test的執行順序問題:
http://blog.csdn.net/d6619309/article/details/52755578
在xml裏面使用<include>指定須要執行的方法和順序
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Preserve order test runs">
<test name="Regression 1" preserve-order="true">
<classes>
<class name="com.pack.preserve.ClassOne">
<methods>
<include name="B" />
<include name="A" />
</methods>
</class>
</classes>
</test>
</suite>

4.Eclipse出現亂碼問題解決
http://blog.csdn.net/tfy1332/article/details/22151491
是由於編碼格式的問題引發的,GBK修改成UTF8格式。

5.Eclipse裏,中文字體過小問題
http://jingyan.baidu.com/article/72ee561aa6bc28e16038df6e.html

6.上傳圖片的怎麼寫?
http://www.cnblogs.com/joewu/p/3701121.html
利用webdriver上傳文件很是方便
 /*上傳文件
  * element,上傳按鈕 例  ("//input[@type='file']")
  * filePath,文件路徑,例 C:\\testContent.pdf
 */
 public void fileUpload(String element, String filePath){
  driver.findElement(By.xpath(element)).sendKeys(filePath);  
 }

7.文件選擇圖片 web

http://blog.csdn.net/xie_0723/article/details/50617100
http://blog.csdn.net/lily_xl/article/details/51723407
http://blog.csdn.net/huilan_same/article/details/52208363

[2017-07-18 16:22:41:192] [videoyiTestCase.ProductManagerTest] [ERROR] [113] [org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=59.0.3071.104)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 50 milliseconds
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'WIN-UBMLJ97RGF8', ip: '172.16.0.108', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir12900_16704}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.104, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 91aae86160d186c5daeec9631c25f830]

http://www.cnblogs.com/qixue/p/3928775.html
打開文件夾後,上傳文件夾不能正常關閉。
http://blog.sina.com.cn/s/blog_539a70d30101ajsg.html
http://www.360doc.com/content/16/0627/09/31226932_571055470.shtml
http://www.360doc.com/content/15/1014/15/20107535_505596449.shtml

3:windows彈窗
例如: chrome

思路: windows

解決的方法能夠經過第三方的工具:autoit 來處理。具體方法請自行百度搜索autoit。
http://www.cnblogs.com/fnng/p/4188162.html
java http://www.cnblogs.com/testlc/p/6069460.html
http://blog.csdn.net/lily_xl/article/details/51723407

將上傳的文件地址參數化:
http://blog.csdn.net/huilan_same/article/details/52208363
經過autoit的獲取對象並編輯腳本:

ControlFocus("文件上傳", "", "Edit1")
WinWait("[CLASS:#32770]", "", 10)
ControlSetText("文件上傳" ,"", "Edit1", $CmdLine[1])
Sleep(2000)app

 


使用方法不正確致使的錯誤
String strUploadExePath = "E:\\Yingpu\\000.SVNYP\\01.我的文件夾\\Renqiang\\04.AutoTest\\videoyiAutoTest\\lib\\uploadFile.exe";
String strResourcePath = "E:\\Yingpu\\000.SVNYP\\01.我的文件夾\\Renqiang\\04.AutoTest\\videoyiAutoTest\\resource\\百科展現圖片_580_660.png";
Runtime.getRuntime().exec(strUploadExePath + " " + strResourcePath);
ide

 

8.得到當前java運行的工做路徑
方便拼接字符串等使用
http://blog.csdn.net/xionglangs/article/details/51085307


9.找不到元素時,報錯
is not clickable at point (209, 606). Other element would receive the click
https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error


10.Chrome已經跑通的Case,在FireFox上上傳文件時,跑不通
[org.openqa.selenium.NoSuchElementException: Element is not currently visible and so may not be interacted with

https://stackoverflow.com/questions/20046783/org-openqa-selenium-nosuchelementexception-no-such-element


11.關閉子窗口
http://blog.csdn.net/gloria0610/article/details/54691685
public static void closeSubWindow(WebDriver driver){
// Get all window handles
Set<String> handles = driver.getWindowHandles();
// Save main Window
String mainWindowhandle = driver.getWindowHandle();
// sub window hanlde
String detailWindowHandle = null;
Iterator<String> iterator = handles.iterator();
while(iterator.hasNext()){
String key = iterator.next();
if (mainWindowhandle.equals(key)){
continue;
}
detailWindowHandle = key;
}
WebDriver detailWindow = driver.switchTo().window(detailWindowHandle);
detailWindow.close();
handles.remove(detailWindowHandle);
driver = driver.switchTo().window(mainWindowhandle);
}

12.WebDriver得到元素的禁用狀態 工具

 之後遇到新的問題,還會記錄。

相關文章
相關標籤/搜索