破碼之拖動滑塊
阿新 • • 發佈:2017-08-18
元素 打開網頁 text con fin odin time click class
#破碼之拖動滑塊 # encoding:utf-8 import selenium import time from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver import ActionChains driver= webdriver.Chrome() # 設定等待時間 wait = WebDriverWait(driver, 30) # 打開網頁 driver.get("http://……") #等待搜索框加載完成傳入搜索關鍵字 input = wait.until(EC.presence_of_element_located((By.XPATH, ‘//*[@id="searchText"]‘))) input.send_keys(u"安徽投資有限責任公司") time.sleep(5) #等待搜索按鈕可點擊,點擊 button = wait.until(EC.element_to_be_clickable((By.XPATH,‘//*[@id="click"]‘))) button.click() time.sleep(5) actions = ActionChains(driver) # 進入搜索頁後,找到滑塊 element = driver.find_element_by_xpath("//div[@class=‘gt_slider_knob gt_show‘]") #鼠標點擊元素並按住不放 actions.click_and_hold(on_element = element).perform() #拖動鼠標到指定的位置,註意這裏位置是相對於元素左上角的相對值 actions.move_to_element_with_offset(to_element = element, xoffset=200, yoffset = 50).perform()# actions.move_to_element(to_element = element).perform() #釋放鼠標 actions.release(on_element = element).perform() time.sleep(3)
破碼之拖動滑塊