zoukankan      html  css  js  c++  java
  • python---滚动条滑动

    '''
    方法:
       drag_and_drop_offset(source,xoffset,yoffset):拖动到某个位置然后松开,用于滑动解锁,属于ActionChains类中的方法
       source:鼠标拖动原始位置
       xoffset:鼠标把元素怒拖动到另外一个位置的x坐标
       yoffset:鼠标把元素拖到到另一个位置的y坐标
       size:获取“大小”的方法
       loaction():获取“位置”的方法
       perform():执行鼠标操作的方法
    
       需求:
           进入淘宝注册页面
           点击同意按钮
           输入手机号
           滚动注册页面滑动条
    '''
    #导包
    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    import time
    #设置浏览器,设置网站
    driver=webdriver.Chrome()
    driver.get("https://reg.taobao.com/member/reg/fill_mobile.htm")
    #设置为最大浏览器
    driver.maximize_window()
    #设置进入下一步时间
    time.sleep(2)
    #出现弹框,点击同意
    driver.find_element_by_xpath('//*[@id="J_AgreementBtn"]').click()
    #设置进入下一步时间
    time.sleep(2)
    #输入手机号
    #清空
    driver.find_element_by_xpath('//*[@id="J_Mobile"]').clear()
    #设置进入下一步时间
    time.sleep(1)
    #输入
    driver.find_element_by_xpath('//*[@id="J_Mobile"]').send_keys("15127918912")
    #设置进入下一步时间
    time.sleep(2)
    #开始执行滚动条
    #获取滚动条大小
    span_backgroud=driver.find_element_by_css_selector('#nc_1__scale_text > span')
    background_size=span_backgroud.size
    #输入滚动条大小的值
    print(background_size)#{'height': 32.0, 'width': 300.0}
    #设置进入下一步时间
    time.sleep(2)
    
    #获取滑块位置
    button=driver.find_element_by_xpath('//*[@id="nc_1_n1z"]')
    button_location=button.location
    #打印滑块的位置
    print(button_location)#{'x': 410, 'y': 295}
    
    #开始拖动
    x_location=button_location["x"]
    y_location=button_location["y"]
    ActionChains(driver).drag_and_drop_by_offset(button,x_location,y_location).perform()
    #设置进入下一步时间
    time.sleep(3)
    #退出
    driver.quit()
    

      

  • 相关阅读:
    那些离不开的 Chrome 扩展插件
    Spring Boot 实战 —— 入门
    Maven 学习笔记
    Linux lvm 分区知识笔记
    Linux 双向 SSH 免密登录
    CentOS Yum 源搭建
    Ubuntu 系统学习
    iOS 测试三方 KIF 的那些事
    Swift 网络请求数据与解析
    iOS Plist 文件的 增 删 改
  • 原文地址:https://www.cnblogs.com/wsx123/p/14228876.html
Copyright © 2011-2022 走看看