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?
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.
Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.
There are four basic components of WebDriver Architecture: Selenium Language Bindings. JSON Wire Protocol. Browser Drivers.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With