Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set new style of element using selenium web-driver

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?

like image 994
Roey Cohen Avatar asked Jul 22 '14 08:07

Roey Cohen


People also ask

What is CSS selector in Selenium WebDriver?

What is a CSS Selector? Essentially, the CSS Selector combines an element selector and a selector value that can identify particular elements on a web page. Like XPath, CSS selector can be used to locate web elements without ID, class, or Name.

How can u switch new window in a Selenium?

Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.

How many types of web Drivers are available in Selenium?

There are four basic components of WebDriver Architecture: Selenium Language Bindings. JSON Wire Protocol. Browser Drivers.

Can we use web element in WebDriver?

There are various techniques using which the WebDriver identifies the WebElements which are based on different properties like ID, Name, Class, XPath, Tagname, CSS Selectors, link Text, etc. WebDriver provides two methods to find the elements on the web page.


1 Answers

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

like image 181
Vignesh Paramasivam Avatar answered Oct 06 '22 18:10

Vignesh Paramasivam