Cannot Get CSS Value from object within iframe


I’m struggling to capture the CSS from an element - any thoughts please?

The element is found within an iframe, so I have an object for iframe and object for element (with iframe as parent).

The iframe looks like this:

<html><head><meta charset="utf-8">
<body id="body" style="margin: 0px;background: red">
  <table style="color: rgb(255, 255, 255); font: bold x-large Arial; height: 100%; width: 100%; text-align: center;"><tbody><tr><td>PRIORITY<br />SERVICES</td></tr></tbody></table>

This appears as a text box with background colour that is either red or white, according to business rule.
My element locator is:

and my script contains this step:
bgcolor = WebUI.getCSSValue(findTestObject(‘Account/DanAdded-MoveLater/lblImportantCustomer’), ‘background’)

I first set the TD as the locator, then tried the table and finally trying the Body itself.
Also tried CSS locator as ‘background’ and also ‘background-color’.
I can get the text from the element but not the CSS value.
Any help appreciated, thanks Dan

Before any interaction with an iframe object, you need to switch to the frame in question.

1 Like

thanks for the reply - I had assumed that that was the case but using ‘Switch to Frame’ gives me exactly the same result: I can ‘get text’ and click an element, whether I use Switch or not.
The only time I can’tt find the element is if I leave the ‘parent iframe’ out of the table object.
The body of the iframe itself contains the style value ‘background’ - I have tried selecting the ‘body’ as an element, also the ‘table’ and also the ‘td’ (there is only one cell in the table).

I have attached a screenshot of the DOM, as I am wondering whether the ‘== $0’ is important.

Thanks again, Dan

You managed to crack it, thanks!
The iframe was not active when I went to get CSS, but I am now able to get CSS value.
I’m a little unsure of behaviour though… since ‘Get Text’ and ‘Click’ worked previously, but not ‘Get CSS value’.

When I changed the parent object value to ‘none’ on my object though, rather than the iframe value, I was suddenly able to get to target the right element. The previous error I got was that ‘Get CSS value’ was unable to find xpath of the actual iframe, rather than the table element. Unsure if this is a bug or expected behaviour - since I would expect ‘Get Text’ to work on the same xpath as ‘Get CSS value’, if same object is used.

I will retry later if there is time.
Thanks again

No problem. I prefer not to use the ‘parent object’ option, it used to be pretty flaky. Like here:

Another thing to consider is to add a wait condition after switching to the iframe and before interacting with anything in the iframe, just in case the element hasn’t been loaded yet.