kfairns
kfairns

Reputation: 3057

Selenium, JavaScript: Extract Element CSS from Active Element

Basically, I want to be able to grab the CSS of the currently active element, so that I can pass that over to the abstraction library that we have, meaning we can use all of the functionality that we've added into our library with the active element.

We can get the active element in WebDriver form using:

driver.switchTo().activeElement();

Is there a way of getting the elements css somehow, without iterating over the numerous possibilities of tags, attributes and parent elements for whatever the active element may be? Or will I have to do a huge amount of looping in order to build up the css?

Upvotes: 0

Views: 83

Answers (1)

GPT14
GPT14

Reputation: 819

driver.switchTo().activeElement(); returns an object of the type WebElement. Passing this WebElement directly to your abstraction library would be simpler than reverse engineering a CSS selector from it.

Upvotes: 1

Related Questions