Selenium+Python:检查属性值

2024-10-01 09:18:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

问题是最后一行。 我想检查一下:

^{pr2}$

不仅是风格本身的存在,还有价值。在

最初是:

style="display:none;"

我想检查一下是不是“阻塞”。在


Tags: thekey代码false元素by属性style
1条回答
网友
1楼 · 发布于 2024-10-01 09:18:07

如果要检查style属性的值,请尝试

if element.get_attribute('style') == 'display: block;':
    validkey = True

或者最好按以下方式进行:

^{pr2}$

相关问题 更多 >