御命丹心

萧瑟悲声秋风起,刹忆寒蝉未鸣时

导航

窗口滑动

'''

#移动到绝对位置
js = "window.scrollTo(0,1000);"
driver.execute_script(js)
sleep(5)
 
#移动到相对位置,移动300,再移动300
js = "window.scrollBy(0,300);"
driver.execute_script(js)
sleep(5)
js = "window.scrollBy(0,300);"
driver.execute_script(js)
sleep(5)
 
#滚动条拖动到浏览器的最下方
js = "window.scrollTo(0, document.body.scrollHeight)"
driver.execute_script(js)
sleep(5)
 
#滚动条拖动到浏览器的最上方
js = "window.scrollTo(0,0);"
driver.execute_script(js)

'''

#下滑动网页
def slide_height(value):
    #获取浏览器Y轴绝对位置
    js = "window.scrollTo(0,1000);"
    driver.execute_script(js)
    sleep(1)
    number = str(value)
    try:
        #for y in range(10):
            #y = value
            # x管水平,y管垂直
            #js = 'window.scrollBy(0,%s)'%(y * 100)
            js = 'window.scrollBy(0,%s)'% value
            driver.execute_script(js)
            print("窗口向下滑动距离 :" + number)
    except Exception as e:
        raise e


#平行滑动网页
def slide_parallel(value):
    #获取浏览器X轴绝对位置
    js = "window.scrollTo(1000,0);"
    driver.execute_script(js)
    sleep(1)
    number = str(value)
    try:
        #for y in range(10):
            #y = value
            # x管水平,y管垂直
            #js = 'window.scrollBy(%s,0)'%(y * 100)
            js = 'window.scrollBy(%s,0)' % value
            driver.execute_script(js)
            print("窗口向右滑动距离 : " + number)
    except Exception as e:
        raise e

#滚动条拖动到浏览器的最下方
def slide_minimum():
    #获取浏览器Y轴绝对位置
    js = "window.scrollTo(0,1000);"
    driver.execute_script(js)
    sleep(1)
    try:
        js = "window.scrollTo(0, document.body.scrollHeight)"
        driver.execute_script(js)
        print("拖动到浏览器底部成功")
    except Exception as e:
        raise e

#滚动条拖动到浏览器的最上方
def slide_highest():
    #获取浏览器Y轴绝对位置
    js = "window.scrollTo(0,1000);"
    driver.execute_script(js)
    sleep(1)
    try:
        js = "window.scrollTo(0,0);"
        driver.execute_script(js)
        print("拖动到浏览器顶部成功")
    except Exception as e:
        raise e

 

posted on 2020-07-10 19:30  正法  阅读(138)  评论(0编辑  收藏  举报