我的常用自定義函數
阿新 • • 發佈:2018-10-07
action driver css 自定義 exc span cto imp webdriver
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 importActionChains
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‘)
我的常用自定義函數