zoukankan      html  css  js  c++  java
  • Selenium---Python3---上传文件

    #上传文件使用send_keys方法添加本地文件
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>upload_file</title>
    <script type="text/javascript" async=""
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css"
    rel="stylesheet" />
    <script type="text/javascript">
    </script>
    </head>
    <body>
    <div class="row-fluid">
    <div class="span6 well">
    <h3>upload_file</h3>
    <input type="file" name="file" />
    </div>
    </div>
    </body>
    <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    </html>
    #coding = utf-8
    
    from selenium import webdriver
    import os,time
    
    #Selenium 下拉框处理
    
    #D:chromedriver_win32chromedriver.exe
    
    class driver_1(object):
        #定义一个对象
        def __init__(self):
            self.driver = webdriver.Chrome('D:chromedriver_win32chromedriver.exe')
    
        def driver_alert(self):
            file_path = 'file:///' + os.path.abspath('upload_file.html')
            self.driver.get(file_path)
            time.sleep(2)
    
            #定位上传按钮,添加本地文件
            self.driver.find_element_by_name('file').send_keys('D:\PycharmProjects1\test.txt')
    
            time.sleep(3)
    
            #退出浏览器
            self.driver.close()
    
    
    if __name__ == "__main__":
        a = driver_1()
        a.driver_alert()
  • 相关阅读:
    pktgen使用指南
    常见的网卡调优
    网络PPS测试
    网络性能测试工具qperf
    设置虚拟机静态IP
    superset填坑
    js格式化
    《你不知道的JavaScript》读书笔记(一):JS是如何查找变量的
    技术分享PPT整理(三):网页渲染流程
    技术分享PPT整理(二):C#常用类型与数据结构
  • 原文地址:https://www.cnblogs.com/aaron456-rgv/p/12718945.html
Copyright © 2011-2022 走看看