模拟鼠标操作的方法,可从 ActionChains 库中调用:
    from selenium.webdriver.common.action_chains import ActionChains

    包含的关于鼠标的操作方法:

    • ‘click(on_element=None)’,鼠标单击
    • ‘click_and_hold(on_element=None)’,鼠标单击后不松开
    • ‘context_click(on_element=None)’,右键单击
    • ‘double_click(on_element=None)’,双击
    • ‘drag_and_drop(source, target)’,拖动到某个元素
    • ‘drag_and_drop_by_offset(source, xoffset, yoffset)’,拖拽到某个坐标然后松开
    • ‘release(on_element=None) ‘,释放鼠标左键
    • ‘move_by_offset(xoffset, yoffset) ‘ 鼠标移动到某个坐标
    • ‘move_to_element(to_element) ‘ 鼠标移动到某元素
    • ‘move_to_element_with_offset(to_element, xoffset, yoffset) ‘ 移动到距某元素左上方多少坐标距离的位置

    包含的关于键盘的方法:

    • ‘key_down(value, element=None) ‘,按下某个键盘上的键
    • ‘key_up(value, element=None) ‘ ,松开某个键
    • ‘send_keys(*args) ‘,发送
    • ‘perform()’,执行已经添加到生成器的操作
    1. for i in range(2000):
    2. ActionChains(dr).key_down(Keys.DOWN). key_up(Keys.DOWN).perform() #相当于一直按着 DOWN 键,下拉页面
    3. print(f'下拉已完成{i}次')