1

I am trying to set attribute to a slider. I am using javascript to automate, I have currently tried the below code,

it('should pan plots when you click and drag', function(done) {
                driver.sleep(2000);

                driver.findElement(webdriver.By.css('._md-slider-wrapper')).click().then(function(){
                driver.findElement(webdriver.By.css('._md-thumb-container')).SetAttribute("style", "left: 22px");
                    done();
                });

but it is not working. I have also tried to pass the element to a function and then try to set the attribute but it didnt work either. i am basically trying to set the value to a slider.

user2987322
  • 177
  • 1
  • 2
  • 10
  • 1
    http://stackoverflow.com/questions/8473024/selenium-can-i-set-any-of-the-attribute-value-of-a-webelement-in-selenium – Satpal Dec 13 '16 at 07:25
  • @user2987322, just extract `Javacsript` line from provided `JavaScriptExecutor` code. There is no other possibility to change element's attribute using `selenium`, except with `JavascriptExecutor`, but as long as you use pure `JavaScript` you don't need "executors" – Andersson Dec 13 '16 at 08:52

1 Answers1

2

Try this:

driver.executeScript("document.querySelector('._md-thumb-container').setAttribute('style', 'left: 22px'");
Linh Nguyen
  • 1,120
  • 7
  • 13
  • If you open the page google.com, and type the commands below in the inspector, what will you see? `document.querySelector("#q")`; `document.querySelector("#q").setAttribute('aria-hidden', 'false')`; `document.querySelector("#q")`; I used the 2nd command to change the attribute `aria-hidden`. For your case, maybe you should try the same to test whether it works or not. – Linh Nguyen Dec 14 '16 at 07:57