码迷,mamicode.com
首页 > 其他好文 > 详细

破码之拖动滑块

时间:2017-08-18 15:51:50      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:driver   offset   off   webdriver   加载   xpath   expect   cat   move   

#破码之拖动滑块
# 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)

 

破码之拖动滑块

标签:driver   offset   off   webdriver   加载   xpath   expect   cat   move   

原文地址:http://www.cnblogs.com/themost/p/7389983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!