【问题标题】:Unable to highlight WebElement in Selenium using JavascriptExecutor for Firefox 35无法使用 Firefox 35 的 JavascriptExecutor 在 Selenium 中突出显示 WebElement
【发布时间】:2015-02-26 19:27:37
【问题描述】:

在执行 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}]

在 Firefox 35 更新后观察到该问题。有解决办法吗?

【问题讨论】:

  • arguments[0]?你指的是什么论据?这当然从来没有奏效。另外,请缩进您的代码。
  • @Tomalak 这曾经在旧版本的 ff 中工作。 arguments[0] 指的是 web 元素 & arguments[1] 指的是样式。请访问stackoverflow.com/questions/10660291/… 中的答案以获取参考。
  • @Tomalak 你能解释一下网页中一些直接可执行的js来突出一个webelement吗?试过arguments[0] 是网络控制台,得到'ReferenceError'
  • 我对@9​​87654326@ 也没有运气。提供您的 html,如果您仍然需要,我会尝试编写一个 javasript。
  • @Saifur 希望有一个适用于任何 html 代码的通用 js。有可能吗?

标签: javascript firefox selenium


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    相关资源
    最近更新 更多