'html - get text color using python selenium?
Anyone know how to get the text color for both "office" and "room"? office_color = "#FD7C04" room_color = "green"
HTML code:
<tr style="background-color:#999" id="tagging">
<td><b style="white-space: nowrap;"> tag_table</b></td>
<td style="text-align:center;">
<span class="big" style="font-size:24px; font-weight:700; color: #FD7C04">office</span></td>
<td style="text-align:center;">
<span class="big" style="font-size:24px; font-weight:700; color: green" id="rigan">room</span></td>
</tr>
Solution 1:[1]
First, get the element you want to extract your atribute from, in this case the span. You choose your prefered method for that. One of them is:
selector="body > span:nth-child(2)"
element1=driver.find_element_by_css_selector(selector)
element2=driver.find_element_by_id("#rigan")
One way to get this is opening the html on your browser, right click on the element and "copy selector" to get a css selector. Then get the atribute from the elements:
color1=element1.get_attribute("color")
color2=element2.get_attribute("color")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pablo Dawson |
