# python-自动化UI测试之- 操作页面滚动条

encoding = utf-8

from selenium import webdriver
import unittest
import traceback
import time

class TestScrollBar(unittest.TestCase):
“”“测试滚动条”""

def setUp(self) -> None:
    self.dr = webdriver.Chrome()
    print('-------测试用例准备就绪--------')

def tearDown(self) -> None:
    self.dr.quit()
    print('--------该测试用例执行完毕--------')

def test_scroll(self):
    try:
        self.dr.get('https://www.jd.com/')
        # 将页面滚动条滑动到页面的最下方
        self.dr.execute_script\
            ('window.scrollTo(100,document.body.scrollHeight);')
        time.sleep(2)

        self.dr.refresh()
        # 将被遮挡的元素滚动到可见屏幕上
        self.dr.execute_script\
            ('document.getElementById("J_feeds").scrollIntoView(true)')
        time.sleep(10)

    except Exception as e:
        print(traceback.print_exc
            (file=open('错误日志\\scrool.log', mode='a', encoding='utf-8')))

if name == ‘main’:
unittest.main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值