• 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()
    

      

  • 相关阅读:
    JS闭包
    webpack管理资源
    在webpack中使用配置文件
    webpack起步
    buuctf-MISC 面具下的flag
    Kali linux Steghide开源隐写工具
    buuctf-misc 九连环
    buuctf-Crypto rsarsa 1
    buuctf-web HardSQL 1
    buuctf-web Hack World 1
  • 原文地址:https://www.cnblogs.com/wsx123/p/14228876.html
Copyright © 2020-2023  润新知