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

    对于通过input标签实现的上传功能,可以将其看作是一个输入框,即通过send_keys()指定本地文件路径的方式实现文件上传。

    创建upfile.html文件,代码如下:

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>upload_file</title>
    <link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" />
    </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://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></scrip>
    </html>
    

    通过浏览器打开upfile.html文件,功能如下图。

    接下来通过send_keys()方法来实现文件上传。

    from selenium import webdriver
    import os
    
    driver = webdriver.Firefox()
    file_path = 'file:///' + os.path.abspath('upfile.html')
    driver.get(file_path)
    
    # 定位上传按钮,添加本地文件
    driver.find_element_by_name("file").send_keys('D:\upload_file.txt')
    
    driver.quit()
    
  • 相关阅读:
    Bessie Goes Moo
    小P的强力值
    Max Flow
    约瑟夫
    Moocryption
    杂务
    排行榜
    银行贷款
    轰炸
    Contaminated Milk
  • 原文地址:https://www.cnblogs.com/Raul2018/p/9389768.html
Copyright © 2011-2022 走看看