Skip to content

Instantly share code, notes, and snippets.

@leeuwe
Last active August 7, 2021 08:55
Show Gist options
  • Save leeuwe/3334a0eb6fac600deb9a200aa17982b2 to your computer and use it in GitHub Desktop.
Save leeuwe/3334a0eb6fac600deb9a200aa17982b2 to your computer and use it in GitHub Desktop.
This git lets you grab the Computed style
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
Check CSS from element
[Documentation] This keyword only works with xpath and is based on [https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle|getComputedStyle]
... You can use this keyword as follows
... | Check CSS from Element | //path/to/element | style | Expected Value |
... | Check CSS from Element | //h2/div | font-size | 24px |
[Arguments] ${xpath} ${CheckStyle} ${ExpectedComputedStyle}
${ComputedStyle} Execute Javascript return document.defaultView.getComputedStyle(document.evaluate("${xpath}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue,null)['${CheckStyle}']
Should Be Equal ${ComputedStyle} ${ExpectedComputedStyle}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment