JavascriptError同时使用Internet Explorer与WebDriverBack

2019-10-17 01:53发布

我使用WebDriverBackedSelenium一个网站的自动化测试,但我的代码工作正常在IE浏览器的Chrome和Firefox,但问题

码是

WebDriver driver = new ChromeDriver();
String baseUrl = "https://mywebsite.com/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.fireEvent("//td[@id='skin_container_logoff']/a/table/tbody/tr/td[2]", "click");

此行给下面的错误

  com.thoughtworks.selenium.SeleniumException: JavaScript error (WARNING: The server did not   
  provide any stacktrace information) Command duration or timeout: 125 milliseconds Build info: 
  version: '2.18.0', revision: '15704', time: '2012-01-27 15:48:16' System info: os.name:   '    
  Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24' Driver info: 
  driver.version: EventFiringWebDriver Command duration or timeout: 735 milliseconds Build info: 
  version: '2.18.0', revision: '15704', time: '2012-01-27 15:49:22' System info: os.name: 
  'Linux', os.arch: 'amd64', os.version: '2.6.32-131.2.1.el6.x86_64', java.version: '1.6.0_26-
   rev' Driver info: driver.version: RemoteWebDriver at     
   org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:42) 
  at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:39) at 
  org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:145) at 
  org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:75) at 
  com.thoughtworks.selenium.DefaultSelenium.fireEvent(DefaultSelenium.java:210) at 
   com.example.tests.WebDriverBackedSeleniumEx.fireEvent(WebDriverBackedSeleniumEx.java:103) at 
  com.example.tests.LoginAdvanceIE.testLoginIE(LoginAdvanceIE.java:48) at 
 com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230) Caused by: 
 org.openqa.selenium.WebDriverException: JavaScript error (WARNING: The server did not provide 
 any stacktrace information) Command duration or timeout: 125 milliseconds Build info: version: 
 '2.18.0', revision: '15704', time: '2012-01-27 15:48:16' System info: os.name: 'Windows 7', 
 os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24' Driver info: driver.version: 
 EventFiringWebDriver Command duration or timeout: 735 milliseconds Build info: version: 
'2.18.0', revision: '15704', time: '2012-01-27 15:49:22' System info: os.name: 'Linux', os.arch: 
'amd64', os.version: '2.6.32-131.2.1.el6.x86_64', java.version: '1.6.0_26-rev' Driver info: 
driver.version: RemoteWebDriver at 
java.lang.reflect.Constructor.newInstance(Constructor.java:513) at 
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147) at 
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113) at 
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:439) at 
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:353) at 



org.openqa.selenium.internal.seleniumemulation.JavascriptLibrary.executeScript(JavascriptLibrary.java
    :88) at 
    org.openqa.selenium.internal.seleniumemulation.FireEvent.handleSeleneseCommand(FireEvent.java:38)   
    at  
    org.openqa.selenium.internal.seleniumemulation.FireEvent.handleSeleneseCommand(FireEvent.java:1) 
    at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:36) 
   Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken Build info: 
   version: '2.18.0', revision: '15704', time: '2012-01-27 15:49:22' System info: os.name: 'Linux', 
    os.arch: 'amd64', os.version: '2.6.32-131.2.1.el6.x86_64', java.version: '1.6.0_26-rev' Driver 
    info: driver.version: RemoteWebDriver at 
    org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:101) Caused by: 
    org.openqa.selenium.WebDriverException: JavaScript error (WARNING: The server did not provide any 
    stacktrace information) Command duration or timeout: 125 milliseconds Build info: version: 
    '2.18.0', revision: '15704', time: '2012-01-27 15:48:16' System info: os.name: 'Windows 7', 
    os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24' Driver info: driver.version: Even
   tFiringWebDriver Build info: version: '2.18.0', revision: '15704', time: '2012-01-27 15:49:22'   
   System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-131.2.1.el6.x86_64', 
java.version: '1.6.0_26-rev' Driver info: driver.version: EventFiringWebDriver at 
java.lang.reflect.Constructor.newInstance(Unknown Source) at 
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147) at 
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113) at 
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:439) at 
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:353) at 
org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:100) at 
$Proxy2.executeScript(Unknown Source) at 

   org.openqa.selenium.support.events.EventFiringWebDriver.executeScript(EventFiringWebDriver.java:208) 
    at org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:54) at 
    org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:1) at 
    java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at 
    java.util.concurrent.FutureTask.run(Unknown Source) at 
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown 
    Source)

我试过WebDriverWait,但我仍然得到错误。

Answer 1:

我不知道这是否是问题,但尽量手工指定的JavaScript超时:

driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);


文章来源: JavascriptError while using Internet Explorer with WebDriverBackedSelenium