如何使用Selify和Python等待元素包含属性style="Display:None;" [英] How to wait for an element to be contain the attribute style="display:none;" using Selenium and Python

查看:0
本文介绍了如何使用Selify和Python等待元素包含属性style="Display:None;"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Selify/Python时,我需要等待/暂停,直到显示:style="display:none;"<div id="notification"..</div>


单击按钮后,将显示以下内容(正在加载..。)

<div id="notification" class="notification_info" style="opacity: 1; display: inline-block;">Loading...</div>

然后,在将数据集加载到网页中后,加载...将消失(通过更改display:none),并出现以下情况:

<div id="notification" class="notification_info" style="display: none;">Loading...</div>


如何完成此操作(检查或等待style="display: none;"的值)?

因为style=display的页面中有很多<divs>,所以我需要同时等待dividstyle display

推荐答案

单击所需按钮后,文本为Loading...的元素将变为可见。因此,您可以看到HTML DOM中的元素为:

<div id="notification" class="notification_info" style="opacity: 1; display: inline-block;">Loading...</div>

加载完成后,通过将style属性的display属性更改为:

,将文本为Loading...的元素变为不可见
style="display: none;"

因此WebElementDOM Tree中表示为:

<div id="notification" class="notification_info" style="display: none;">Loading...</div>

解决方案

使用Selenium等待文本为Loading...的元素变为style="display: none;",您需要为invisibility_of_element()诱导WebDriverWait,您可以使用以下Locator Strategies之一:

  • 使用CSS_SELECTOR

    WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div.notification_info#notification")))
    
  • 使用XPATH

    WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='notification_info' and @id='notification']")))
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

参考

您可以在以下位置找到相关的详细讨论:

这篇关于如何使用Selify和Python等待元素包含属性style=&quot;Display:None;&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆