2

While executing the script used to highlight and reset a WebElement in selenium 2.43:

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 returns error:

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}]

Observed the issue after Firefox 35 update. Is there a workaround?

riaz
  • 21
  • 5
  • 1
    `arguments[0]`? What arguments do you refer to? This certainly has never worked. Also, please indent your code. – Tomalak Jan 25 '15 at 09:51
  • @Tomalak this used to work in older ver of ff. arguments[0] refers to the webelement & arguments[1] refers to the style. Visit the answer in http://stackoverflow.com/questions/10660291/highlight-elements-in-webdriver-during-runtime for ref.. – riaz Jan 25 '15 at 10:41
  • @Tomalak can you explain some directly executable js in a webpage to highlight a webelement? tried `arguments[0]` is web console, got 'ReferenceError' – riaz Jan 25 '15 at 13:04
  • I also had no luck with `arguments[0]`. provide your html I would try to write a javasript if you still needed. – Saifur Jan 25 '15 at 17:36
  • @Saifur would like to have a universal js applicable to any html code. Is it possible? – riaz Jan 27 '15 at 18:03
  • Not sure what do you mean by that. But, the javascript can be different depending on the element. Provide the html if you want me to write one example for you – Saifur Jan 27 '15 at 18:09
  • Elaborating.. I would like to use a unified method across my test script in Selenium. Should be able to call it any time, I want to highlight an webelement. – riaz Jan 27 '15 at 18:53
  • It's a known bug ~ https://code.google.com/p/selenium/issues/detail?id=8390. Just waiting on the next selenium release (probably 2.44.1) – Phil Jan 29 '15 at 03:26
  • @Phil Thanks! Hope they fix it in 2.44.1 – riaz Jan 31 '15 at 10:05

1 Answers1

0

I also faced the same issue when running with firefox 35. I downgraded this to firefox 33, which worked for me.(https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/33.0/mac/en-US/)

Selenium server version 2.44.0 with firefox 33 resolved this issue.

Barani r
  • 2,119
  • 1
  • 25
  • 24