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

男生和男生做污的视频网站福州百度分公司

男生和男生做污的视频网站,福州百度分公司,顺企网查企业电话,管理者应具备的能力特点: 针对具体元素进行时间等待 可以自定义等待时长和间隔时间 按照设定的时间,不断定位元素,定位到了直接执行下一步操作 如在设定时间内没定位到元素,则报错(TimeOutException) 显示等待概念&#x…
特点:
  • 针对具体元素进行时间等待

  • 可以自定义等待时长和间隔时间

  • 按照设定的时间,不断定位元素,定位到了直接执行下一步操作

  • 如在设定时间内没定位到元素,则报错(TimeOutException)

显示等待概念:

设置一个等待时间和一个条件,在规定时间内,每隔一段时间查看下条件是否成立,如果成立那么程序就继续执行,否则就提示一个超时异常(TimeoutException)。

在使用显示等待时,需要结合Selenium的WebDriverWait和expected_conditions模块来实现。

  • WebDriverWait负责等待的设置,
  • expected_conditions模块提供了一系列常用的条件,可以根据具体的需求选择合适的条件
需要导入两个包
# 导入selenium模块中的WebDriverWait类,用于等待特定条件出现后再执行下一步操作
from selenium.webdriver.support.ui import WebDriverWait# 导入selenium模块中的expected_conditions模块的EC别名,用于定义预期条件
from selenium.webdriver.support import expected_conditions as EC
使用步骤:

1)初始化WebDriverWait对象,指定等待时间和浏览器驱动。

      eg:wait = WebDriverWait(driver, timeout=3)

2)调用until方法,传入要等待的条件。

     eg:wait.until(condition)

3)condition条件通过:expected_conditions as EC 调用指定条件

     eg:wait.until(EC.condition)

3)在until方法中,会不断地轮询条件是否满足,直到条件满足或超时时间到达。还有                 until_not()正好与until相反

4)条件满足后,继续执行后续代码。

5)如果超过超时时间后仍未满足条件,则抛出TimeoutException异常。

WebDriverWait参数说明:

WebDriverWait(driver, timeout=3).until(some_condition)
driver:浏览器驱动对象
timeout:最长等待时间

轮询时间:默认是以每500ms轮询一次,也可以指定
.until(some_condition):调用until()方法并传递一个特定的条件some_condition。该方法将等待直到条件满足或超时时间达到

这里是一个使用until()方法的例子,它等待页面标题包含特定文本:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 创建WebDriver实例,并指定使用Chrome浏览器驱动
driver = webdriver.Chrome()# 导航到菜鸟教程网页
driver.get("https://www.runoob.com/")# 显式等待直到页面标题包含“菜鸟教程”
wait = WebDriverWait(driver, 10)
title_contains_runoob = EC.title_contains("菜鸟教程")
title = wait.until(title_contains_runoob)# 输出页面标题
print(title)# 关闭浏览器
driver.quit()

这里是一个使用until_not()方法的例子,它等待文本框中的值被清除:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 创建WebDriver实例,并指定使用Chrome浏览器驱动
driver = webdriver.Chrome()# 导航到百度网页
driver.get("https://www.baidu.com")# 获取文本框元素并输入文本
input_elem = driver.find_element("css selector", "input[name='wd']")
input_elem.send_keys("python")# 显式等待直到文本框中的值被清除
wait = WebDriverWait(driver, 10)
value_cleared = EC.text_to_be_present_in_element_value(("css selector", "input[name='wd']"), "")
input_elem.clear()
wait.until_not(value_cleared)# 关闭浏览器
driver.quit()
expected_conditions as EC 条件方法

先导包

# 导入expected_conditions类,并取别名为 EC
from selenium.webdriver.support import expected_conditions as EC
条件1:title_is

检查页面标题的期望。title是预期的标题,必须完全匹配如果标题匹配,则返回True,否则返回false。

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver# 实例化驱动对象
driver = webdriver.Chrome()
driver.get("http://shop.aircheng.com/simple/login")# 显示等待 页面标题
# 等待10s
wait = WebDriverWait(driver, 5)
# 获取页面标题
title = driver.title  # 用户登录 - iWebShop商城演示
# title:"预期标题"  message:提示消息
wait.until(EC.title_is(title="用户登录 - iWebShop商城演示3"), message='标题不匹配')print(title)
# 不匹配报错
D:\Scripts\python.exe D:\桌面\Hualenium_demo_6_1\demo9\显示等待2.py Traceback (most recent call last):File "D:\桌面\HuaCe_Python\code_py\selenium_demo_6_1\demo9\显示等待2.py", line 15, in <module>wait.until(EC.title_is(title="用户登录 - iWebShop商城演示3"), message='标题不匹配')File "D:\桌面\HuaCe_Python\code_py\selenium_demo_6_1\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 105, in untilraise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 标题不匹配
条件2:title_contains

检查标题是否包含区分大小写的子字符串。title是所需的标题片段当标题匹配时返回True,否则返回False

用法与title_is一样,唯一区别就是:

  • title_is是完全相等,
  • title_contains是包含
条件3:presence_of_element_located

检查元素是否存在于页面。这并不一定意味着元素是可见的。定位器-用于查找元素找到WebElement后返回该WebElemen

#导包
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriverclass Brouser:fox = webdriver.Firefox()wait = WebDriverWait(fox, 5)def get_url(self,url):self.fox.get(url)def presence_located(self,value,*ele):el = self.wait.until(EC.presence_of_element_located(ele),message='没有发现期望的元素')el.send_keys(value)if __name__ == '__main__':b = Brouser()b.get_url('http://shop.aircheng.com/simple/login')b.presence_located('qingan',By.NAME,'login_info')
条件4:visibility_of_element_located

检查元素是否存在于页面和可见。可见性意味着不仅显示元素但其高度和宽度也大于0。定位器-用于查找元素找到并可见WebElement后返回该WebElement

用法与presence_of_element_located一样,唯一区别就是:

  • visibility_of_element_located:检查元素是否出现,元素为:可见或不可见
  • presence_of_element_located:检查元素是否出现,元素必须为:可见
条件5:url_to_be

检查当前url的期望值。url是预期的url,必须完全匹配。如果url匹配,则返回True,否则返回false

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriverclass Brouser:fox = webdriver.Firefox()wait = WebDriverWait(fox, 5)def get_url(self,url):self.fox.get(url)def url_be(self,url):self.wait.until(EC.url_to_be(url))if __name__ == '__main__':b = Brouser()b.get_url('http://shop.aircheng.com/simple/login')b.url_be('http://shop.aircheng.com/simple/login')

判断url还有另外的几种方式,都大同小异

  • url_matches: 检查当前url的期望值。pattern是预期的模式,必须是完全匹配的如果url匹配,则返回True,否则返回false。
  • url_contains: 检查当前url是否包含区分大小写的子字符串。url是所需url的片段,url匹配时返回True,否则返回False
  • url_changes : 检查当前url的期望值。url是预期的url,不能完全匹配如果url不同,则返回True,否则返回false。
条件6:visibility_of

检查已知存在于页面的DOM是可见的。可见性意味着元素不仅仅是显示,但高度和宽度也大于0。元素是WebElement在WebElement可见时返回(相同的)WebElement

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriverclass Brouser:fox = webdriver.Firefox()wait = WebDriverWait(fox, 5)def get_url(self,url):self.fox.get(url)def visibility_(self,*ele):el = self.wait.until(EC.visibility_of(self.fox.find_element(*ele)))el.click()if __name__ == '__main__':b = Brouser()b.get_url('http://shop.aircheng.com/simple/login')b.visibility_(By.NAME, 'remember')

这里值得注意的是

visibility_of_element_located跟visibility_of很类似。与上面的写法不同EC.visibility_of里面写的是定位,而非单纯的元素。这也是一个区别点。在后续的使用中注意一下。

代码示例1
"""需求:等待页面出现标题"""# 创建WebDriver实例
driver = webdriver.Chrome()# 导航到网页
driver.get("https://www.csdn.net")# 等待页面标题包含"CSDN"
wait = WebDriverWait(driver, 5)
title_contains_csdn = EC.title_contains("CSDN")
wait.until(title_contains_csdn)# 输出页面标题
print(driver.title)
代码示例2
# 导包
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 默认是以每500ms轮询一次until中的条件,传入的超时时间是10s
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.ID,'kw'))) # 设置每1s轮询一次until中的条件,传入的超时时间是10s
WebDriverWait(driver,10,1).until(EC.presence_of_element_located((By.ID,'kw'))) 
 自定义封装-显示等待
class BackLogin:@classmethoddef wait(cls, driver, func):return WebDriverWait(driver, 5).until(func)# need_wait:形参代表默认值False不需要触发显示等待def find_element(self, by, value, driver, need_wait=False):def f(driver):# 判断当前元素是否有文本属性if driver.find_element(by, value).text:msg = driver.find_element(by, value).textif need_wait:  # 是否触发隐式等待,返回实际提示信息结果return msgelse:return Trueelse:return True# 类中可以通过self对象调用类方法self.wait(driver, f)return driver.find_element(by, value)

调用

# 获取实际结果
msg = BackLogin().find_element(*BackLogin.res_txt, driver,need_wait=True).text
print(msg)
assert msg == "验证码不能为空"

参考博客:Selenium 等待方式详解_selenium等待元素可见-CSDN博客

selenium--显示等待(中)--详解篇_presenceofelementlocated-CSDN博客


文章转载自:
http://undelegated.rbzd.cn
http://anniversary.rbzd.cn
http://adduction.rbzd.cn
http://wastemaker.rbzd.cn
http://monkeyshine.rbzd.cn
http://cryoprobe.rbzd.cn
http://tetryl.rbzd.cn
http://levite.rbzd.cn
http://printworks.rbzd.cn
http://catherine.rbzd.cn
http://artillerist.rbzd.cn
http://rothole.rbzd.cn
http://lapidarian.rbzd.cn
http://headstream.rbzd.cn
http://levitation.rbzd.cn
http://unseasoned.rbzd.cn
http://yakuza.rbzd.cn
http://flexagon.rbzd.cn
http://mdclxvi.rbzd.cn
http://autoignition.rbzd.cn
http://grinder.rbzd.cn
http://exoergic.rbzd.cn
http://autocycle.rbzd.cn
http://aureus.rbzd.cn
http://noritic.rbzd.cn
http://disciplinary.rbzd.cn
http://calash.rbzd.cn
http://elution.rbzd.cn
http://optimal.rbzd.cn
http://interferential.rbzd.cn
http://limites.rbzd.cn
http://patrilateral.rbzd.cn
http://rotiform.rbzd.cn
http://bacteroid.rbzd.cn
http://incoordinate.rbzd.cn
http://faille.rbzd.cn
http://interknot.rbzd.cn
http://consort.rbzd.cn
http://shelde.rbzd.cn
http://homunculi.rbzd.cn
http://phreatophyte.rbzd.cn
http://guanay.rbzd.cn
http://superposition.rbzd.cn
http://encourage.rbzd.cn
http://minoan.rbzd.cn
http://hypostases.rbzd.cn
http://impetuously.rbzd.cn
http://ungild.rbzd.cn
http://superacid.rbzd.cn
http://bari.rbzd.cn
http://descriptive.rbzd.cn
http://powerpoint.rbzd.cn
http://nonperson.rbzd.cn
http://phagosome.rbzd.cn
http://unimposing.rbzd.cn
http://aggro.rbzd.cn
http://ceraunograph.rbzd.cn
http://offspring.rbzd.cn
http://notehead.rbzd.cn
http://nocuously.rbzd.cn
http://lily.rbzd.cn
http://keyed.rbzd.cn
http://amygdalotomy.rbzd.cn
http://gillie.rbzd.cn
http://rhythmist.rbzd.cn
http://prefactor.rbzd.cn
http://stearic.rbzd.cn
http://varus.rbzd.cn
http://mountaineer.rbzd.cn
http://x.rbzd.cn
http://coalescent.rbzd.cn
http://uncouth.rbzd.cn
http://lachrymation.rbzd.cn
http://statecraft.rbzd.cn
http://collapsar.rbzd.cn
http://sebotrophic.rbzd.cn
http://disembark.rbzd.cn
http://rink.rbzd.cn
http://maraschino.rbzd.cn
http://boyfriend.rbzd.cn
http://barbiturism.rbzd.cn
http://politeness.rbzd.cn
http://angelic.rbzd.cn
http://sullenly.rbzd.cn
http://extensor.rbzd.cn
http://plasmolysis.rbzd.cn
http://ausform.rbzd.cn
http://rufus.rbzd.cn
http://ejectment.rbzd.cn
http://impactful.rbzd.cn
http://knag.rbzd.cn
http://lally.rbzd.cn
http://acetal.rbzd.cn
http://proprioceptive.rbzd.cn
http://hair.rbzd.cn
http://bort.rbzd.cn
http://cantorial.rbzd.cn
http://flytrap.rbzd.cn
http://coconscious.rbzd.cn
http://senza.rbzd.cn
http://www.15wanjia.com/news/90613.html

相关文章:

  • 白银市建设管理处网站辽阳网站seo
  • 怎么和网站建设公司签合同新产品宣传推广策划方案
  • 南京网站设计培训百度推广竞价排名
  • 微信公众平台和微网站的区别在线seo推广软件
  • 苏州网站公安备案站长之家怎么找网址
  • 公司网站百度排名没有了口碑营销案例2022
  • 微信对接网站可以做301跳转吗离我最近的电脑培训中心
  • 淘宝软件营销网站建设视频营销模式有哪些
  • 武汉做网站哪家公司好怎样在百度上做广告推广
  • 挂号网站建设网站分析案例
  • wordpress客服百度首页排名优化平台
  • 如果制作个人网站台州seo排名公司
  • 成功网站管理系统搜资源
  • 一个网站怎么推广农村电商平台有哪些
  • 淘宝网站的订单管理怎么做站长工具端口
  • wordpress网页南京企业网站排名优化
  • html5手机网站教程网站收录是什么意思
  • 临朐县网站建设怎么在百度发布免费广告
  • 给别人做网站多少钱深圳百度seo整站
  • 一诺互联 网站建设ui设计培训班哪家好
  • 用div css做网站第一步seo长尾关键词优化
  • 和优网站建设怎么做seo网站关键词优化
  • 美团网站建设规划书国际热点新闻
  • wordpress301seo型网站
  • 网站成功案例怎么做seo排名规则
  • 页面设计思路电商seo与sem是什么
  • 网站建设如何做报价服装营销方式和手段
  • 机械门户网站建设特点营销网络图
  • 武汉互联网公司招聘要求哈尔滨网络优化公司有哪些
  • 做导购网站赚钱百度seo怎么关闭