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()
  • 相关阅读:
    jQuery 如何存储,获取和删除 Cookies
    mysql调用存储过程出现Illegal mix of collations错误
    vim IDE
    android 播放Raw文件夹下的音乐文件
    7种形式的Android Dialog使用举例
    Chronometer 计时器使用
    获取屏幕,适应屏幕
    android 碎片
    安卓开发者必备的42个链接
    自定义TabActivity,TabActivity的美化
  • 原文地址:https://www.cnblogs.com/aaron456-rgv/p/12718945.html
Copyright © 2011-2022 走看看