8

I am building test plan using (selenium webdriver - java) for page that contain button which open small color selection window.

this is the code of the right panel of the color selection window:

<span class="ui-colorpicker-bar-layer-pointer">  
<span class="ui-colorpicker-bar-pointer" style="top: 51.0333px;"></span>

the question is how can i set new style..... , i found this solution:

JavascriptExecutor js = (JavascriptExecutor) driver;
 js.executeScript("document.getElementById('colorPickIcon').setAttribute('style', '22.3333px')");

and it doesn't work....any advice's?

Roey Cohen
  • 329
  • 2
  • 5
  • 17

1 Answers1

13

You can use findElement instead of getElementById,

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.id("colorPickIcon"));
js.executeScript("arguments[0].setAttribute('style', 'top:22.3333px')", element);

You can refer the link How to use JavaScript with Selenium WebDriver Java

Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57
  • thanks , i tried this and its still not working... its Compiled but the style doesn't change ... – Roey Cohen Jul 22 '14 at 14:49
  • 1
    For styles it is better to use like it shown here: http://stackoverflow.com/questions/17911980/selenium-with-python-how-to-modify-an-element-css-style. This code couldn't work. – Jury Feb 01 '16 at 08:52