Dilip Agheda
Dilip Agheda

Reputation: 2547

Selenium- How to validate if the element has certain styles

I need to write a test script to validate that a button is present on the page and the button becomes sticky and stays attached at the bottom of the screen for mobile breakpoint.

I have already written a script where it resizes the browser window. However, How do i prove that a button remains sticky to the footer no matter how much scrolling user does.

Button retains its id and place in the DOM when its styling changes for the mobile view.

I need solution for all major browsers but if someone can guide me for Chrome that should be good enough.

I have looked into getComputedStyle but i think its bit messy. i am looking for more elegant solution using some library.

Upvotes: 0

Views: 572

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20057

This check is baked in selenium - there's a webelement method isDisplayed() returning a boolean. Here's a link to the Java bindings - https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isDisplayed--

And if you're wandering if this is a "real" check is the element in the viewport, here's the webdriver's explanation how it's done - https://w3c.github.io/webdriver/#element-displayedness (in summary: yes, as much as this can be done).

Upvotes: 1

Related Questions