2017-09-19 46 views
0

瀏覽器:IE11 IEDriver:IEDriverServer_x64_3.3.0 代碼片段:IEDriver總是thows NoSuchElementException異常

public class DownloadinIE 
{ 
    long timeout = 1000; 
    public String classname = this.getClass().getSimpleName(); 
    String date = new SimpleDateFormat("yyyy_MM_dd_HH").format(Calendar.getInstance().getTime()).toString(); 
    String downloadPath = \\ur download path; 
    public WebDriver driver; 

    @BeforeMethod 
    public void setup() 
    { 
System.setProperty("webdriver.ie.driver","\\IEDriverServer.exe"); 
     driver = new InternetExplorerDriver(); 
    } 
    @Test 
    public void download() throws InterruptedException 
    { 
     driver.get("https://www.eclipse.org/downloads/?"); 
     Thread.sleep(10000); 
     driver.findElement(By.cssSelector("[title='64 bit Download']")).click(); 
     Thread.sleep(3000); 
     driver.findElement(By.cssSelector(".fa.fa-download")).click(); 
     Thread.sleep(3000); 
     BaseLibrary.verifyFileDownloaded(downloadPath); 
    } 
} 

錯誤信息:如果文件下載完畢

org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == .fa.fa-download (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 961 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46' 
System info: host: 'A', ip: '192.168.0.102', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_74' 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:17524/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}] 
Session ID: f75c788e-f130-4531-9f0a-a4bc714d9e76 
*** Element info: {Using=css selector, value=.fa.fa-download} 
    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.findElement(RemoteWebDriver.java:363) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:492) 
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355) 
    at reports.WaitAndDownloadIE.download(WaitAndDownloadIE.java:45) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:669) 
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877) 
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201) 
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 
    at org.testng.TestRunner.privateRun(TestRunner.java:776) 
    at org.testng.TestRunner.run(TestRunner.java:634) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:425) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:334) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1243) 
    at org.testng.TestNG.runSuites(TestNG.java:1161) 
    at org.testng.TestNG.run(TestNG.java:1129) 
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) 

verifyFileDownloaded方法驗證。我的問題是驅動程序沒有從第一個元素單擊直接識別任何對象。此測試在Firefox和Chrome中運行良好。這裏有什麼問題?請提供您的建議。

我的應用程序需要在IE中測試以獲得類似的功能。這就是爲什麼我這樣試圖

+0

Web驅動程序與Java – crawler

回答

0

請確保您的InternetExplorer =>互聯網選項=>安全所有被禁用或水平低。這幫助了我。

+0

感謝您的回覆。你的建議是強制性的在IE中運行,我接受它。但在我的情況下,它並沒有幫助,我嘗試了另一種方法,它運行良好 – crawler

相關問題