一、Expected_conditions模块源码分析-7

1、expected_conditions模块

  • 可以获取title
  • 可以获取元素

2、expected_conditions模块这么强大,到底是怎么做的呢?

3、title_is是返回两个相同的title

  • 调用title_is这个方法/类,用你的title和它自身的title做比较。
  • 如果两个title是一样的,返回true,否则为false。
class title_is(object):
    """An expectation for checking the title of a page.
    title is the expected title, which must be an exact match
    returns True if the title matches, false otherwise."""
    def __init__(self, title):
        self.title = title

    def __call__(self, driver):
        return self.title == driver.title

 

4、title_contains

  • 传递一个title进来。
  • 判断此title是否在driver.title中。
  • 存在,则返回true,否则为false。
class title_contains(object):
    """ An expectation for checking that the title contains a case-sensitive
    substring. title is the fragment of title expected
    returns True when the title matches, False otherwise
    """
    def __init__(self, title):
        self.title = title

    def __call__(self, driver):
        return self.title in driver.title

 

5、presence_of_element_located

  • 判断此元素是否存在于结构中。并不一定是展示出来的。
  • presence_of_element_located里面调用了_find_element方法。
  • _find_element方法里调用了driver.find_element方法。
class presence_of_element_located(object):
    """ An expectation for checking that an element is present on the DOM
    of a page. This does not necessarily mean that the element is visible.
    locator - used to find the element
    returns the WebElement once it is located
    """
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        return _find_element(driver, self.locator)

 

6、url_contains

  •  判断当前地址driver.current_url中包含指定内容self.url。
class url_contains(object):
    """ An expectation for checking that the current url contains a
    case-sensitive substring.
    url is the fragment of url expected,
    returns True when the url matches, False otherwise
    """
    def __init__(self, url):
        self.url = url

    def __call__(self, driver):
        return self.url in driver.current_url

 

7、presence_of_all_elements_located

  • 检测至少一个元素在结构中。
class presence_of_all_elements_located(object):
    """ An expectation for checking that there is at least one element present
    on a web page.
    locator is used to find the element
    returns the list of WebElements once they are located
    """
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        return _find_elements(driver, self.locator)

 

posted @ 2022-08-26 14:39  酱汁怪兽  阅读(47)  评论(0编辑  收藏  举报