Reputation: 3042
I have an HTML table that I need to not only get the text in any of the rows. But I would also like to get each and every row's background-color. By using the inspector I can see the "tr class" definition and I already know (and can also verify) that the name "minor" means yellow background (#fff455).
But when I tried to get the row's attributes, by using selenium, I only get None as a result. I have tried to use both the CSS Selector:
row0_fault = browser.find_element_by_css_selector("tr.minor")
and the tag name:
faultTable_rows = Fault_Table.find_elements_by_tag_name("tr")
in order to refer to the whole row. And then I tried
get_attribute("background-color")
but without any success.
Here is the relevant inspector screen capture:
What am I doing wrong ? How can I get the background-color that stands behind the name "minor" ?
Upvotes: 0
Views: 1359
Reputation: 50819
You can use value_of_css_property()
to get the color as rgb( , , )
row0_fault = browser.find_element_by_css_selector("tr.minor")
row0_fault.value_of_css_property('background-color')
To convert it to hex you can follow this answer.
Upvotes: 2