#破码之拖动滑块 # 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)
时间: 2024-11-07 23:33:17