zoukankan      html  css  js  c++  java
  • Selenium2+Python--等待页面元素加载(wait)

    在进行web自动化的时候,受页面加载速度影响比较大,常常会报element not found的错误。selenium1.0 中提供了selenium.isElementPresent(Xpath),用于判断xpath是否存在,存在就执行操作,不存在就可以等待一定的时间段。在webDriver中提供了WebDriverWait类,可以智能的等待页面元素加载完成再执行操作。


    利用这个类就可以实现智能等待的效果:

         wait = WebDriverWait(webdriver.chrome(),30)

      elm = wait.until(lambda x: x.find_element_by_xpath(Xpath))

      elm.click()

    再提供一个判断元素存在否:

      def isPresent(self):
      try: driver.find_element_by_xpath(Xpath)
      except NoSuchElementException, e: return False
      return True

  • 相关阅读:
    odoo权限
    odoo开发bug记录
    odoo视图
    odoo13线上发布
    odoo开发环境搭建
    request
    urllib
    b站排行榜-爬虫
    DockerFile
    Docker基本操作
  • 原文地址:https://www.cnblogs.com/ysjt/p/6564827.html
Copyright © 2011-2022 走看看