0

I'm writing automated tests with Selenium Javascript WebDriver. I'd like to know how I can modify CSS on the page.

http://code.google.com/p/selenium/wiki/WebDriverJs

So far, I'm able to get DOM elements, click them, or type text into input fields.

driver.findElement(webdriver.By.css("#myid"));
webElem.click();
webElem.sendKeys();

I'm stuck right now with a problem that one of the input field type is hidden. So when I try to do webElem.sendKeys() I get this Error:

"Element is not clickable at point"

I'd like to change the type of this input field from "hidden" to "text" so that I can call sendKeys on it. I couldn't find any documentation on how to do that.

4
  • Why? If it's hidden is it really the element you actually want to interact with? Does a particular user action cause that element to become displayed? What would a user need to do to actually populate that input field? Commented Aug 12, 2014 at 20:27
  • User would need to move a slider which would cause the value of that input field to change, I don't really know how to drag a slider with selenium besides I feel like changing input value directly is an easier option. Commented Aug 12, 2014 at 20:40
  • It isn't life like, and if these tests are supposed to be used for automatic CI regression tests, you need them to be as user & life like as possible. I would find out how you change the slider personally. What makes up the slider? Is it a standard scroll bar? A jquery plugin? Commented Aug 12, 2014 at 20:42
  • No its a yui plugin, regardless the complexity of doing that is not worth the hassle, I need to test different scenarios by providing different input values. Changing input values will do the job here. Commented Aug 12, 2014 at 21:09

1 Answer 1

1

You can execute Javascript like this:

var webdriver = require('selenium-webdriver');
var driver = new webdriver
    .Builder()
    .withCapabilities(webdriver.Capabilities.chrome())
    .build();

driver.executeScript('/* document.getElementById etc. */');

However in principle, I agree with Arran in the comments above.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this worked, I changed CSS property of that element by injecting javascript. But this seems like a hacky solution. Is there a way to actually change page CSS by using webdriver APIs?
You can get attributes, but not set them as far as I know.

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.