0

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?

4
  • 1
    When you say CSS, do you mean the CSS selector or the CSS properties of the active element? Commented May 30, 2018 at 15:35
  • @GPT14 I do indeed Commented May 30, 2018 at 15:36
  • 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. Commented May 30, 2018 at 15:48
  • I guess I could implement a way to include a web element or a locator... That would definitely work, and would definitely mean less code than trying to reverse engineer the CSS selector. If you post that as an answer, I'll be happy to accept and upvote it. Commented May 30, 2018 at 15:52

1 Answer 1

1

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.

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

Comments

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.