0

I use selenium's webdriverJS to automate some things on an html5 page. I had to use a css selector for putting it into a function. I can fetch some elements with xpath like this:

var complexXpath = "//*/div/a";     /* not the xpath, but an example here */
var element = mydriver.findElement(mywebdriver.By.xpath(complexXpath));

Is it possible to fetch now the css of that element, so I can use it into another javascript function that uses only css ? Something like

var b = element.getCSS();
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Bart Vanherck
  • 343
  • 2
  • 10

1 Answers1

0

When you want to get all classes of an object, use element.classList

Demo: http://jsfiddle.net/XWUQ3/

<div id="first" class="one two three hi"></div>
alert(document.getElementById("first").classList);

It even implements: .contains(x), .add(x), .remove(x), .toggle(x)

https://developer.mozilla.org/en-US/docs/Web/API/Element.classList

Nico O
  • 13,762
  • 9
  • 54
  • 69