2016-11-10 29 views
1

この障害を乗り越えるにはちょっと迷っています。私はKijijiの代理人をつくろうとしています。Macにいるときにファイルのアップロードを処理する方法については固執しています。私はSeleniumの画像/ファイルアップロード

driver.find_element_by_id('ImageUploadButton').send_keys(image) 

を実行しようとしました。しかしそれは、私はそれが理由Kijijiはの特別なファイルアップロードのかもしれないと信じて、何もしていないようですが、私はこのハードルを乗り越えるするかどうかはわかりません。

誰もこれまでに行ったことはありますか?

彼らの「ソースの表示」ページのコード:あなたが代わりにボタンの「ファイル」input要素ターゲットにする必要がある

<div id="ImageUpload" class="clearfix form-section placeholders"> 

    <p class="images-title">Add at least one photo. Use more to show different angles and details.</p> 
     <ol id="UploadedImages"> 
     </ol> 

    <span class="field-message" data-for="FileUploadInput"></span> 

      <div id="ImageDragAndDrop" class="clearfix"> 
       <div class="image"></div> 
       <div class="copy"> 
        <h3>Drag and Drop</h3> 
        <p>Drag and drop to change the order of your pictures.</p> 
       </div> 
      </div> 

      <div id="FileInputWrapper" class="file-input-wrapper"> 
       <input type="hidden" name="file" id="FileUploadInput" > 

       <h3>Get at least twice the number of replies by uploading images</h3> 
       <p>You can upload a maximum of <span id="MaxImages">10</span> photos, that are at least 300px wide or tall (we recommend at least 1000px).</p> 

       <button id="ImageUploadButton" type="button" class="button-update-cancel short file-upload-button"> 
        Select Images</button> 
      </div> 
     <input type="hidden" name="images"> 
    </div> 
+0

は 'ファイル入力要素 – Andersson

+0

用HTML'コードを提供するここでのスクリーンショットです。 http://imgur.com/a/BRueF –

+0

'button'型の要素にテキストを送ることはできません。ページの '要素を確認してください – Andersson

答えて

0

image_input = driver.find_element_by_id("FileUploadInput") 

を、問題は、このです要素が隠され、送信キーはそのまま動作しません。この問題を解決するには、に必要最初の要素が見えるように:

driver.execute_script("arguments[0].type = 'file';", image_input) 
image_input.send_keys(image) 
関連する問題