zoukankan      html  css  js  c++  java
  • 文件上传+滚动条操作+执行js代码

    1、文件上传2中场景    直接send_keys(file_path)      第二种通过三方调用(调用浏览器之外的系统需要进行等待time.sleep())

    from pywinauto import Desktop
    app = Desktop()
    dialog = app['打开']    #根据名字找到弹出窗口
    dialog["Edit"].type_keys(file_path)     # 在输入框中输入值
    dialog["Button"].click()
    #linux系统下
    import pyautogui
    import pyperclip
    
    pyperclip.copy(file_path)
    
    time.sleep(2)
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('enter', presses=2)
    
    time.sleep(2)
    

    2、滚动条

    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://readhub.cn/topics")
    
    # 滑动到页面最底部
    
    for i in range(5):
        js_code = 'window.scrollTo(0, document.body.scrollHeight);'
        driver.execute_script(js_code)
    
    time.sleep(3)
    

      

    """滚动条滚动到当前元素"""
    # 先定位 常见问题
    el = driver.find_element_by_link_text("常见问题")
    # 把 常见问题的元素 滑动的可见范围内
    el.location_once_scrolled_into_view
    

     3、执行js代码

    e = driver.find_element_by_id("train_date")
    
    # 发送 js code 给浏览器
    js_code = """e = document.getElementById("train_date");"""
    driver.execute_script(js_code)
    
    time.sleep(0.2)
    js_code = """e.readOnly = false;"""
    driver.execute_script(js_code)
    
    time.sleep(0.2)
    js_code = """e.value = "2020-07-20";"""
    driver.execute_script(js_code)
    

      

  • 相关阅读:
    nginx 详解
    阿里云 消息队列mq
    手机浏览器Yandex安装插件说明
    windows下JAVA环境变量配置
    共享文件夹免密登入
    自动添加静态路由
    加入WSUS补丁服务器并下载补丁
    加入时间同步服务器(NTP)
    更改rdp端口
    关闭及开启445等危险端口
  • 原文地址:https://www.cnblogs.com/XXQQ123/p/13402685.html
Copyright © 2011-2022 走看看