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

万网 网站托管如何快速进行网站开发

万网 网站托管,如何快速进行网站开发,泉州企业建站程序,个人小程序免费制作平台#x1f345; 视频学习#xff1a;文末有免费的配套视频可观看 #x1f345; 点击文末小卡片#xff0c;免费获取软件测试全套资料#xff0c;资料在手#xff0c;涨薪更快 time.sleep(3) 固定等待3秒 driver.implicitly_wait(10) 隐性的等待#xff0c;对应全局 WebD… 视频学习文末有免费的配套视频可观看 点击文末小卡片免费获取软件测试全套资料资料在手涨薪更快 time.sleep(3) 固定等待3秒 driver.implicitly_wait(10) 隐性的等待对应全局 WebDriverWait( driver, timeout).until(‘有返回值的__call__()方法或函数’) 显性的等待对应到元素 一、time.sleep(seconds) 固定等待 import time time.sleep(3) #等待3秒 time.sleep(seconds) seconds参数为整数单位秒。 它是Python的time提供的休眠方法。 常用于短时间的等待为了自动测试用例的执行效率固定等待的时间需要控制在3秒内。在用例中尽量少用固定等待。 二、智能隐性的等待implicitly_wait回应超时等待 driver.implicitly_wait(time_to_wait) 回应超时等待隐性的设置后对应的是全局如查找元素。 driver.implicitly_wait(10) # 设置全局隐性等待时间单位秒 每次driver执行 找不到元素都会等待设置的时间它的值设置的过长对用例执行效率有很大的影响必须在执行完成之后还原回来。driver.implicitly_wait() 要慎之又慎的使用。 driver对它的默认值为0driver.implicitly_wait(0)能还原隐性等待的设置时间。 三、智能显性等待WebDriverWait WebDriverWait(driver, timeout, poll_frequency0.5, ignored_exceptionsNone) 参数说明 driver 为webdriver驱动timeout 最长超时时间单位(秒)poll_frequency 循环查找元素每次间隔的时间默认0.5秒ignored_exceptions 超时后需要输出的异常信息 WebDriverWait()下面有两个方法可用until()和until_not() WebDriverWait(driver, timeout).until(method, message) method 函数或者实例__call__()方法返回True时停止否则超时后抛出异常。 参数说明 method 在等待时间内调用的方法或者函数该方法或函数需要有返回值并且只接收一个参数driver。 message 超时时抛出TimeoutException将message传入异常显示出来 WebDriverWait(driver, timeout).until_not(method, message) 于上面的until() 相反until_not 中的method函数或者实例__call__()方法返回False结束否则抛出异常。 until方法使用的method 的函数或者类__call()__方法详解 函数我们一般采用匿名函数lambda 。 lambda driver:driver.find_element(定位元素) # 当定位的元素时为True无元素时为False。如示例1、2 WebDriverWait示例1 WebDriverWait(driver,5).until(lambda driver:driver.find_element_by_id(query)) 5秒内等待元素(idquery)出现lambda driver:driver.find_element_by_id(query) 为一个匿名函数只有一个driver参数返回的是查找的元素对象。 WebDriverWait示例2 WebDriverWait(driver, 5).until_not(lambda driver:driver.find_element_by_name(query)) 定义类中的__call()__方法。 class wait_element(object):def __init__(self, locator):self.locator locatordef __call__(self, driver):return driver.find_element(self.locator)WebDriverWait(driver, 5).until(wait_element((By.ID, query))) # 等待元素出现 WebDriverWait(driver, 5).until_not(wait_element((By.ID, query))) # 等待元素消失 wait_element类中__init__()方法接收需要定位的元素__call__()方法中只能有唯一变量driver并且返回元素对象。 这样做是是不是很麻烦其实selenium提供的一个库进行操作expected_conditions库。引入位置 from selenium.webdriver.support import expected_conditions as ec它囊括了我们需要使用等待的所有情况。 四、expected_conditions 类库 from selenium.webdriver.support import expected_conditions as ec # 引入包 下面示例都是以搜狗搜索首页为例。 方法中参数说明 locator(By.ID, id) 表示使用By方法定位元素的元组element表示获取的webElement元素对象。 ec.title_is(‘title’) 判断页面标题等于title ec.title_contains(‘title’) 判断页面标题包含title WebDriverWait(driver, 10).until(ec.title_is(搜狗搜索引擎 - 上网从搜狗开始)) # 等待title 于参数相等 WebDriverWait(driver, 10).until(ec.title_contains(搜狗搜索引擎)) # 等待title 包含 参数的内容 ec.presence_of_element_located(locator) 等待locator元素是否出现 ec.presence_of_all_elements_located(locator) 等待所有locator元素是否出现 WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.ID, query))) WebDriverWait(driver, 10).until(ec.presence_of_all_elements_located((By.ID, query))) ec.visibility_of_element_located(locator) 等待locator元素可见 ec.invisibility_of_element_located(locator) 等待locator元素隐藏 ec.visibility_of(element) 等待element元素可见 WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.ID, query))) WebDriverWait(driver, 10).until(ec.presence_of_all_elements_located((By.ID, query))) ec.text_to_be_present_in_element(locator,text) 等待locator的元素中包含text文本 ec.text_to_be_present_in_element_value(locator,value) 等待locator元素的value属性为value WebDriverWait(driver, 10).until(ec.text_to_be_present_in_element((By.ID, erwx), 搜索APP)) # 等待元素中包含搜索APP文本 WebDriverWait(driver, 10).until(ec.text_to_be_present_in_element_value((By.ID, query),selenium)) # 等待元素的值为 selenium一般用于输入框 ec.frame_to_be_available_and_switch_to_it(locator) 等待frame可切入 WebDriverWait(driver, 10).until(ec.frame_to_be_available_and_switch_to_it((By.ID, frame))) WebDriverWait(driver, 10).until(ec.frame_to_be_available_and_switch_to_it(frameid)) ec.alert_is_present() 等待alert弹出窗口出现 WebDriverWait(driver, 10).until(ec.alert_is_present()) ec.element_to_be_clickable(locator) 等待locator元素可点击 WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.ID, kw))) 等待元素被选中一般用于复选框,单选框 ec.element_to_be_selected(element) 等待element元素是被选中 ec.element_located_to_be_selected(locator) 等待locator元素是被选中ec.element_selection_state_to_be(element, is_selected) 等待element元素的值被选中为is_selected(布尔值) ec.element_located_selection_state_to_be(locator,is_selected) 等待locator元素的值是否被选中is_selected(布尔值) from selenium import webdriver import time from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as ec # 引入包 from selenium.webdriver.common.by import Bydriver webdriver.Chrome() driver.maximize_window() driver.get(rhttps://www.baidu.com/) driver.find_element_by_link_text(设置).click() WebDriverWait(driver, 3).until(ec.element_to_be_clickable((By.LINK_TEXT, 搜索设置))) # 等待搜索可点击不可缺少 driver.find_element_by_link_text(搜索设置).click() element driver.find_element_by_id(s1_1) WebDriverWait(driver, 2).until(ec.element_to_be_selected(element)) # element被选中 WebDriverWait(driver, 10).until(ec.element_located_to_be_selected((By.ID, SL_0))) # id’SL_0’ 被选中 WebDriverWait(driver, 10).until(ec.element_selection_state_to_be(element,True )) # element 被选中 WebDriverWait(driver, 10).until(ec.element_located_selection_state_to_be((By.ID, SL_1), False)) # id’SL_1’不被选中 time.sleep(3) driver.quit() 五、什么时候使用等待 固定等待sleep与隐性等待implicitly_wait尽量少用它会对测试用例的执行效率有影响。 显性的等待WebDriverWait可以灵活运用什么时候需要用到 1、页面加载的时候确认页面元素是否加载成功可以使用WebDriverWait 2、页面跳转的时候等待跳转页面的元素出现需要选一个在跳转前的页面不存在的元素 3、下拉菜单的时候如上百度搜索设置的下拉菜单需要加上个时间断的等待元素可点击 4、页面刷新的时候 总之页面存在改变的时候页面上本来没的元素然后再出现的元素 同时在这我为大家准备了一份软件测试视频教程含面试、接口、自动化、性能测试等就在下方需要的可以直接去观看。 字节大佬一周讲完自动化测试项目实战这套教程是怎么称霸B站的【2024最新版】
http://www.pierceye.com/news/997491/

相关文章:

  • php做网站验证码的设计电商网站的二级怎么做
  • 广西网站建设价钱微信crm管理系统
  • 福州网站建设公司中小企业荆门市城乡建设管理局网站
  • 建设信用卡网站首页有做车身拉花的网站吗
  • 怎么做婚恋网站织梦网站推广插件
  • rtt全民互助平台网站开发自己怎样做免费网站
  • 建站模板东营建网站公司
  • 如何用vs做网站网络推广方案下拉管家微xiala11
  • 可以做彩票广告的网站吗做网站的应用
  • 龙岗网站 建设深圳信科湘潭做网站价格品牌磐石网络
  • 湖北网站排名优化安卓项目开发
  • 网站怎么引入微信支付郑州官方通报
  • 在南宁做家教兼职的网站北京通州做网站
  • 深圳网站的建设维护公司秦皇岛市建设局官网
  • 做网站 插件静态网站开发课程相关新闻
  • 网站建站 公司无锡搜索引擎营销的内容
  • 公司网站建设小知识单页网站是什么样子的
  • 大学网站建设排名深圳网站建设公司报价
  • 贵阳网站制作公司茶叶推广方案
  • 自适应 网站开发wordpress域名邮箱设置
  • 深圳网站设计网站制作非织梦做的网站能仿吗
  • 做网站可以使用免费空间吗沧州百姓网免费发布信息网
  • 关于阅读类网站的建设规划书使用密码访问wordpress文章
  • 做鲜花配送网站需要准备什么郑州官网网站优化公司
  • 评论网站建设个人网站域名名字
  • 郑州做茶叶的网站科技公司官网设计源代码
  • 武夷山住房和城乡建设部网站广东建设报网站
  • 怎样建设网站是什么样的免费软件不收费网站
  • 网站服务器如何管理seo知名公司
  • 网站单页别人是怎么做的预约挂号php网站ftp急着后台密码忘记了