自动化测试之上下滑动选择日期

  解决思路:通过 ActionChains类实现上下滑动选择日期。

  测试网址:http://www.jq22.com/yanshi4976

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
driver.get("https://www.jq22.com/yanshi4976")
time.sleep(2)
driver.switch_to.frame("iframe")
driver.find_element(By.ID, "appDate").click()

# 定位滑动的年、月、日
dwwo = driver.find_elements(By.CLASS_NAME, "dwwo")
year = dwwo[0]
month = dwwo[1]
day = dwwo[2]

action = webdriver.ActionChains(driver)
action.drag_and_drop_by_offset(year, 0, 30).perform()
action.drag_and_drop_by_offset(month, 0, 30).perform()
action.drag_and_drop_by_offset(day, 0, 30).perform()

  switch_to.frame:切换到指定frame中
  action.drag_and_drop_by_offset(element, x, y):单元素拖动,x, y 表示的元素拖动时横向和纵向移动的距离,单位为像素,element表示的是元素对象,移动的像素最终要比在web页面中看到的移动像素值要大,最好大于5个像素或者10像素。

 

 

posted @ 2022-07-08 22:00  MToy  阅读(165)  评论(0)    收藏  举报