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)
    

      

  • 相关阅读:
    0_Simple__simplePrintf
    0_Simple__simplePitchLinearTexture
    0_Simple__simpleP2P
    0_Simple__simpleOccupancy
    0_Simple__MultiGPU
    0_Simple__simpleMultiCopy
    0_Simple__simpleMPI
    0_Simple__simpleLayeredTexture
    0_Simple__simpleCubemapTexture
    0_Simple__simpleCooperativeGroups
  • 原文地址:https://www.cnblogs.com/XXQQ123/p/13402685.html
Copyright © 2011-2022 走看看