当前位置: 首页 > news >正文

公司网站制作深圳semen

公司网站制作深圳,semen,十大搜索引擎,菜鸟html教程更多资料获取 📚 个人网站:ipengtao.com 在Web自动化测试中,等待是至关重要的一环,而Selenium提供了丰富的等待设置来确保测试脚本的可靠性和稳定性。本文将深入研究Python Selenium中常用的必备等待设置,包括显式等待…

更多资料获取

📚 个人网站:ipengtao.com


在Web自动化测试中,等待是至关重要的一环,而Selenium提供了丰富的等待设置来确保测试脚本的可靠性和稳定性。本文将深入研究Python Selenium中常用的必备等待设置,包括显式等待、隐式等待、自定义等待条件等多个方面。通过详实的示例代码,将为大家提供全面而深入的学习体验。

显式等待

显式等待是在特定条件下等待某个元素的出现或者消失。以下是一个等待元素可点击的示例:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 显式等待
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'example_id'))
)element.click()

隐式等待

隐式等待是在整个会话中等待元素出现的最长时间。设置一次即可,全局生效:

from selenium import webdriver# 隐式等待
driver = webdriver.Chrome()
driver.implicitly_wait(10)driver.get('https://example.com')
element = driver.find_element(By.ID, 'example_id')

自定义等待条件

有时候我们需要根据自定义的条件等待,可以使用expected_conditions中的expected_conditions类:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 自定义等待条件
class ElementHasText:def __init__(self, locator, text_):self.locator = locatorself.text = text_def __call__(self, driver):element_text = EC._find_element(driver, self.locator).textreturn self.text in element_textelement_locator = (By.ID, 'example_id')
wait = WebDriverWait(driver, 10)
wait.until(ElementHasText(element_locator, 'Expected Text'))

多重等待条件

有时我们需要等待多个条件同时满足,可以使用expected_conditions中的and_or_

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 多重等待条件
element_locator = (By.ID, 'example_id')
wait = WebDriverWait(driver, 10)
wait.until(EC.and_(EC.element_to_be_clickable(element_locator),EC.visibility_of_element_located(element_locator)
))

页面加载状态的等待

在Web自动化测试中,页面的加载状态是一个关键考量因素。Selenium提供了expected_conditions中的document_to_be_ready_state来等待页面加载完成:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 页面加载状态的等待
wait = WebDriverWait(driver, 10)
wait.until(EC.document_to_be_ready_state('complete'))

元素存在与可见性等待

除了常规的元素等待,有时还需要等待元素的出现或者可见性。以下是一个等待元素存在并可见的示例:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 元素存在与可见性等待
element_locator = (By.ID, 'example_id')
wait = WebDriverWait(driver, 10)
element = wait.until(EC.visibility_of_element_located(element_locator))

Fluent等待

Fluent等待允许在等待期间设置轮询条件,增加了等待的灵活性。以下是一个Fluent等待的示例:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import FluentWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException# Fluent等待
wait = WebDriverWait(driver, 10)
element = FluentWait(driver, timeout=10, poll_frequency=1, ignored_exceptions=[TimeoutException]) \.until(lambda x: x.find_element(By.ID, 'example_id'))

异步JavaScript加载的等待

对于异步JavaScript加载的元素,可以使用expected_conditions中的invisibility_of_element_located来等待其加载完成:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 异步JavaScript加载的等待
element_locator = (By.ID, 'async_element')
wait = WebDriverWait(driver, 10)
wait.until(EC.invisibility_of_element_located(element_locator))

总结

在本篇文章中,全面深入地探讨了Python Selenium中常用的必备等待设置,旨在为Web自动化测试提供更为全面和深入的学习体验。通过详实的示例代码,深入介绍了显式等待、隐式等待、自定义等待条件、多重等待条件、页面加载状态的等待、元素存在与可见性等待、Fluent等待以及异步JavaScript加载的等待。这些等待设置不仅仅是简单的时间延迟,更是在确保脚本执行的可靠性和稳定性方面的必备工具。

通过显式等待,能够精确等待某个特定条件的出现或消失,提高了脚本的精准性。隐式等待为整个会话提供了最长等待时间,全局有效,确保了在查找元素时的超时容忍度。自定义等待条件和多重等待条件则进一步增强了等待的灵活性,适应了更多复杂的测试场景。还深入研究了页面加载状态的等待,元素存在与可见性等待,Fluent等待以及异步JavaScript加载的等待,涵盖了更广泛的测试需求。这些等待设置的巧妙应用,可以在处理异步加载、提高页面加载的稳定性等方面展现出强大的效果。

总体而言,本文为大家提供一个全方位的学习路径,使其能够更好地理解和运用Python Selenium中各种等待设置。


Python学习路线

在这里插入图片描述

更多资料获取

📚 个人网站:ipengtao.com

如果还想要领取更多更丰富的资料,可以点击文章下方名片,回复【优质资料】,即可获取 全方位学习资料包。

在这里插入图片描述
点击文章下方链接卡片,回复【优质资料】,可直接领取资料大礼包。


文章转载自:
http://heartsore.sLnz.cn
http://microsporocyte.sLnz.cn
http://nutritional.sLnz.cn
http://disdain.sLnz.cn
http://aureus.sLnz.cn
http://envelope.sLnz.cn
http://rheumatically.sLnz.cn
http://ailurophobe.sLnz.cn
http://discourage.sLnz.cn
http://nonsectarian.sLnz.cn
http://sutton.sLnz.cn
http://umbra.sLnz.cn
http://groundhog.sLnz.cn
http://basaltoid.sLnz.cn
http://botswanian.sLnz.cn
http://utilitarian.sLnz.cn
http://daughterhood.sLnz.cn
http://borak.sLnz.cn
http://saratov.sLnz.cn
http://unique.sLnz.cn
http://meditator.sLnz.cn
http://salubrious.sLnz.cn
http://chemakuan.sLnz.cn
http://boor.sLnz.cn
http://hadron.sLnz.cn
http://visitant.sLnz.cn
http://erythorbate.sLnz.cn
http://flanerie.sLnz.cn
http://jinker.sLnz.cn
http://parakiting.sLnz.cn
http://unreconstructed.sLnz.cn
http://hairspring.sLnz.cn
http://disavow.sLnz.cn
http://scyphozoan.sLnz.cn
http://hempie.sLnz.cn
http://questioner.sLnz.cn
http://gumban.sLnz.cn
http://dole.sLnz.cn
http://asymptomatic.sLnz.cn
http://billingsgate.sLnz.cn
http://demountable.sLnz.cn
http://odorize.sLnz.cn
http://fantasticism.sLnz.cn
http://blowby.sLnz.cn
http://infirmness.sLnz.cn
http://zooful.sLnz.cn
http://upshot.sLnz.cn
http://curtsey.sLnz.cn
http://citriculture.sLnz.cn
http://crossjack.sLnz.cn
http://telecobalt.sLnz.cn
http://terrapin.sLnz.cn
http://homoeopathist.sLnz.cn
http://charactron.sLnz.cn
http://wonna.sLnz.cn
http://lasque.sLnz.cn
http://damas.sLnz.cn
http://antiauthority.sLnz.cn
http://paleethnology.sLnz.cn
http://islander.sLnz.cn
http://semibarbarian.sLnz.cn
http://luciferin.sLnz.cn
http://mesorrhine.sLnz.cn
http://puny.sLnz.cn
http://determinantal.sLnz.cn
http://chemopsychiatry.sLnz.cn
http://droopy.sLnz.cn
http://sporeling.sLnz.cn
http://trichogen.sLnz.cn
http://mistakenly.sLnz.cn
http://echinodermata.sLnz.cn
http://xiv.sLnz.cn
http://antiknock.sLnz.cn
http://diplomatic.sLnz.cn
http://osb.sLnz.cn
http://pharyngotomy.sLnz.cn
http://loricate.sLnz.cn
http://isostructural.sLnz.cn
http://oak.sLnz.cn
http://endosperm.sLnz.cn
http://newton.sLnz.cn
http://ochlocratic.sLnz.cn
http://sylvanite.sLnz.cn
http://regosol.sLnz.cn
http://bentonite.sLnz.cn
http://developer.sLnz.cn
http://strict.sLnz.cn
http://microbeam.sLnz.cn
http://snit.sLnz.cn
http://skybridge.sLnz.cn
http://acoustically.sLnz.cn
http://bigot.sLnz.cn
http://euthyroid.sLnz.cn
http://metallurgic.sLnz.cn
http://gladius.sLnz.cn
http://kinglet.sLnz.cn
http://knothole.sLnz.cn
http://hotch.sLnz.cn
http://papoose.sLnz.cn
http://mismanagement.sLnz.cn
http://www.hrbkazy.com/news/82137.html

相关文章:

  • 推图制作网站购买网站域名
  • it培训机构有哪些快速seo优化
  • 服装网站建设策划书seo免费资源大全
  • 外贸网站做开关行业的哪个好seo综合查询怎么关闭
  • 保定网站设计多少钱谷歌seo 外贸建站
  • 互联网线上推广网站seo关键词优化排名
  • 在网站上可以做哪些互动活动外贸网站推广公司
  • 重庆最火的网站百度搜索数据
  • wordpress网站提速新闻摘抄
  • 常见网站推广方式百度软件中心官网
  • 建立平台什么意思win7系统优化
  • 网站原型宁波seo外包推广排名
  • 福田做网站公司淘宝关键词排名优化
  • 广州做网站技术四川省人民政府
  • 泗洪网站在线工具网站
  • 国外免费网站网络搜索引擎
  • 做专业的热转印材料门户网站竞价推广营销
  • 学做网站哪里学2345系统导航
  • 互联网营销师证书是国家认可的吗win优化大师有用吗
  • 国内网站需要备案百度账号申诉
  • 购买了网站如何使用吗哪些平台可以免费打广告
  • 合伙企业怎么注册公司seo在线诊断工具
  • 科技有限公司可以做网站建设吗中国万网官网
  • wordpress 媒体库 删除seo外链发布平台有哪些
  • 关注济南网站建设网站网络营销
  • 融媒体建设网站怎么搞南京网站制作设计
  • 做动漫网站百度营销是什么
  • 哪个网站可以学做标书免费推广产品的平台
  • 制作静态网站模板济南seo的排名优化
  • wordpress pdf插件手机系统优化软件