python - Selenium +Python : check attribute value

标签 python selenium web attributes styles

我想检查元素中存在的属性的值。

我有以下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/

相关文章:

python - 属性错误 : 'bytes' object has no attribute 'encode' ; base64 encode a pdf file

c# - headless (headless)模式下的 Firefox 以小尺寸运行(1366、768)

java - 使用 Selenium 和 Java 单击按钮时出现问题

docker swarm 不会重新启动不健康的 Selenium 集线器容器

user-interface - 如何在 Web 应用程序中维护状态——因为 HTTP 是无状态的

javascript - 网络音频 API : Why can you only start sources once?

python - 单击 Tkinter Treeview 小部件的项目的命令?

python - 使用scrapy,如何获取部分xpath解析结果?

python - 列表值在应保持不变的地方发生变化

javascript - 在网页中使用 zxing Barcode Scanner