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.

2
  • 1
    stackoverflow.com/questions/8473024/… Commented Dec 13, 2016 at 7: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" Commented Dec 13, 2016 at 8:52

1 Answer 1

2

Try this:

driver.executeScript("document.querySelector('._md-thumb-container').setAttribute('style', 'left: 22px'");
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.