无法使用 Firefox 35 的 JavascriptExecutor 突出显示 Selenium 中的 WebEle

Unable to highlight WebElement in Selenium using JavascriptExecutor for Firefox 35

本文关键字:显示 Selenium WebEle 中的 JavascriptExecutor Firefox      更新时间:2023-09-26

在执行用于突出显示和重置 Selenium 2.43 中的 WebElement 的脚本时:

public void highlightElement(WebElement element) {
  String originalStyle = element.getAttribute("style");
  JavascriptExecutor js = (JavascriptExecutor) selenium;
  js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element,
				                "color: red; border: 5px solid red;");
  try {
    Thread.sleep(3000);
  } catch (InterruptedException e) {}
  js.executeScript("arguments[0].setAttribute('style', '" + originalStyle + "');", element);
}

Eclipse 返回错误:

org.openqa.selenium.WebDriverException: arguments[0] is undefined
Command duration or timeout: 74 milliseconds
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=35.0}]

在火狐 35 更新后观察到此问题。有解决方法吗?

我在使用 Firefox 35 运行时也遇到了同样的问题。 我将其降级为对我有用的Firefox 33。(https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/33.0/mac/en-US/)

带有Firefox 33的Selenium服务器版本2.44.0解决了这个问题。