擅长:python、mysql、java
<p>你在找<code>value_of_css_property('background-color')</code>:</p>
<pre><code>rgb = find_element_by_class_name("bar").value_of_css_property('background-color')
</code></pre>
<p>但是,这将返回字符串<code>rgb(221, 81, 76)</code>。为了得到它的十六进制值,可以使用@unutbu的答案:</p>
<pre><code>import re
...
rgb = find_element_by_class_name("bar").value_of_css_property('background-color')
r,g,b = map(int, re.search(
r'rgb\((\d+),\s*(\d+),\s*(\d+)', rgb).groups())
color = '#%02x%02x%02x' % (r, g, b)
</code></pre>
<p>你的十六进制是字符串。</p>