2014-01-30 50 views
0

我嘗試使用從xPathsOnClick Chrome擴展程序獲得的xpaths。在ChromeChrome中的xpath點擊失敗

/html/body/div[@id='content']/section[@id='landing']/button[@class='wide'] 
//section[@id='landing']/button[@class='wide'] 

System.out.println("clicking xpath"); 
driver.findElement(By.xpath("//section[@id='landing']/button[@class='wide']")).click(); 
Thread.sleep(2000); 
System.out.println("clicking xpath again");  
driver.findElement(By.xpath("//section[@id='landing']/button[@class='wide']")).click(); 
Thread.sleep(2000);  

但是都沒有成功然後我試圖通過使用Selenium IDE,它記錄了這個點擊FireFox中記錄點擊生成腳本。這工作,當我運行用我JUNIT4測試Firefox的驅動程序中的硒腳本,但沒有當我使用ChromeDriver:

driver.findElement(By.cssSelector("button.wide")).click(); 

但我需要運行我的鉻試驗。什麼可能導致我的腳本在Chrome中失敗,但不是在FireFox中?

這是我的堆棧跟蹤,當這個錯誤返回。

org.openqa.selenium.NoSuchElementException: no such element 
    (Session info: chrome=32.0.1700.102) 
    (Driver info: chromedriver=2.8.241036,platform=Mac OS X 10.9.1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 30.04 seconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.37.1', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42', time: '2013-10-21 09:08:07' 
System info: host: 'xxxxxxxxxxxx.local', ip: 'xxxxxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.1', java.version: '1.7.0_40' 
Session ID: 80610629a5bacb30e815dacc5077693a 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/0n/n2fztz7x2ssdk6fncrw2csk02pm9vz/T/.org.chromium.Chromium.AHvKDM}, rotatable=false, locationContextEnabled=true, version=32.0.1700.102, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396) 
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:431) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299) 
    at com.thelathe.FactorTrack_selenium.testFactorTrack(FactorTrack_selenium.java:31) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

我把了Thread.sleep(5000)立即在點擊方法的前面,但它仍然具有相同的消息

​​
+0

什麼是失敗?不點擊?拋出異常? – Richard

+0

哦,是的抱歉,我沒有包括堆棧跟蹤,在這裏。我清理了我的電腦名稱和IP地址 –

+0

您是否嘗試過等待元素?它可能沒有加載到你點擊它的時間。 – Husam

回答

0

的問題是錯誤的元素是一個iFrame後面。它不需要我通過iFrame進行測試,所以我能夠解決我的問題。