我的常用自定义函数

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
driver=['1','2']
def EC_located(presence_of,value):
    '''
     目的:简化代码长度
    :param presence_of:EC.判断方法
    :选择一个可以使用EC_located(presence_of_element_located,value)
    :选择一组可使用EC_located(presence_of_elements_located,value)
    :param value:要找的值
    :return:选择到的对象
    '''
    wait = WebDriverWait(driver_list[0], 10)
    try:
        EC.presence_of_elements_located
        ecl=wait.until(EC.presence_of((By.CSS_SELECTOR,value)))
        return ecl
    except TimeoutException:
        print(value,'1元素未加载成功,等待超时')
def open_chrome():
    driver[0]=webdriver.Chrome()
    driver[0].get('http://www.baidu.com')

猜你喜欢

转载自www.cnblogs.com/zhangdingqu/p/9750331.html