Beispiel #1
0
def input_value(by, locator, value):
    try:
        element = get_element(driver, by, locator)
        # element.click()
        element.send_keys(value)
    except Exception as e:
        raise e
                    ec.frame_to_be_available_and_switch_to_it(
                        (self.byDic[by.lower()], locator)))
            else:
                raise TypeError('未找到定位方式,请确保定位方式正确')
        except Exception as e:
            raise e

    def visibility_of_element_located(self, by, locator):
        """显示等待页面元素出现在dom中, 并且可见, 存在则返回该元素对象"""
        try:
            if by.lower() in self.byDic:
                self.wait.until(
                    ec.visibility_of_element_located(
                        (self.byDic[by.lower()], locator)))
            else:
                raise TypeError('未找到定位方式,请确保定位方式正确')
        except Exception as e:
            raise e


if __name__ == '__main__':
    d = webdriver.Firefox()
    d.get('https://mail.126.com')
    wait = WaitUnit(d)
    wait.frame_to_be_available_and_switch_to_it(
        'xpath', "//div[@id='loginDiv']/iframe")
    wait.visibility_of_element_located('xpath', "//input[@name='email']")
    u_name = get_element(d, 'xpath', "//input[@name='email']")
    u_name.send_keys('python')
    d.quit()
Beispiel #3
0
def click_btn(by, locator):
    try:
        get_element(driver, by, locator).click()
    except Exception as e:
        raise e
Beispiel #4
0
def clear(by, locator):
    try:
        get_element(driver, by, locator).clear()
    except Exception as e:
        raise e
Beispiel #5
0
def switch_to_frame(by, locator):
    try:
        driver.switch_to.frame(get_element(driver, by, locator))
    except Exception as e:
        raise e
Beispiel #6
0
def assert_error_info(by, locator, string):
    element = get_element(driver, by, locator)
    text = element.text
    assert text == string