我想检查元素中存在的属性的值。
我有以下Python代码:
validkey = False
# Was the key valid.
element = w.find_element_by_id('registerkey_form')
# Is the activation message is shown, meaning it was successful in activation.
if element.get_attribute('style'):
validkey = True
问题出在倒数第二行。 我想检查:
style="display:block;"
不仅仅是风格本身的存在,还有值(value)。
原来是:
style="display:none;"
我想检查它是否被“阻止”。
最佳答案
如果您想检查 style
属性的值,请尝试
if element.get_attribute('style') == 'display: block;':
validkey = True
或者更好地执行以下操作:
if element.value_of_css_property('display') == 'block':
validkey = True
关于python - Selenium +Python : check attribute value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53792432/