• WebDriver 滑动解锁---(虫师《selenium3自动化测试实战--基于Python语言笔记26》)


    1.滑动解锁

    例1:https://www.helloweba.net/demo/2017/unlock/中的滑动解锁

    代码如下:

     slide-to-unlock-handle:表示滑块

    slide-to-unlock-progress:滑过后的背景色

    from time import sleep
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from selenium.common.exceptions import UnexpectedAlertPresentException
    
    driver = webdriver.Chrome()
    driver.get("https://www.helloweba.net/demo/2017/unlock/")
    
    # 定位滑块
    slider = driver.find_element_by_class_name("slide-to-unlock-handle")
    action = ActionChains(driver)
    action.click_and_hold(slider).perform()  # click_and_hold()单击并按下鼠标左键
    
    for index in range(200):
        try:
            action.move_by_offset(5, 0).perform()  # move_by_offset()移动鼠标,第一个参数为x坐标距离,第二个参数为y坐标距离
        except UnexpectedAlertPresentException:
            break
        action.reset_actions()  # 重置action
        sleep(0.1)  # 等待停顿时间
    
    # 打印警告框提示
    success_text = driver.switch_to.alert.text
    print("success_text")

     2.上下滑动选择

    例2:上下滑动选择日期:http://www.jq22.com/yanshi4976

    from time import sleep
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("http://www.jq22.com/yanshi4976")
    sleep(2)
    driver.switch_to_frame("iframe")
    driver.find_element_by_id("appDate").click()
    
    # 定位要滑动的年月日
    dwwos = driver.find_element_by_class_name("dwwo")
    year = dwwos[0]
    month = dwwos[1]
    day = dwwos[2]
    
    action = webdriver.TouchActions(driver)
    action.scroll_from_element(year, 0, 5).perform()  # scroll_from_element 滑动元素
    action.scroll_from_element(month, 0, 30).perform()
    action.scroll_from_element(day, 0, 30).perform()
  • 相关阅读:
    使用XE7并行库中的TTask(转)
    Delphi xe7并行编程快速入门(转)
    Pre-compile (pre-JIT) your assembly on the fly, or trigger JIT compilation ahead-of-time (转)
    使用RemObjects Pascal Script (转)
    Remobjects SDK 服务器搭建
    toString()方法
    环境变量
    jstl标签学习
    SQL的各种join
    Mybatis的一些配置
  • 原文地址:https://www.cnblogs.com/kite123/p/11532484.html
Copyright © 2020-2023  润新知