如何使用Selify和Python等待元素包含属性style="Display:None;"

发布时间:2022-08-25 / 作者:清心寡欲
本文介绍了如何使用Selify和Python等待元素包含属性style=";display:None;";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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

Loading...

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


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

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

推荐答案

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

Loading...

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

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

因此WebElement在DOM Tree中表示为:



解决方案

使用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
    

参考

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

  • How to click on anchor element with selenium using python?
  • Selenium invisibilityOf(element) method throwing NoSuchElementException + WebDriverWait.ignoring(NoSuchElementException.class) is not working

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



[英文标题]How to wait for an element to be contain the attribute style="display:none;" using Selenium and Python


声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。