簡體   English   中英

Selenium-python/ 嘗試通過選擇上傳按鈕並將圖像路徑作為文本發送來上傳圖像,但我什么也沒得到

[英]Selenium-python/ trying to upload an image by selecting the upload button and sending the path of the image as text but I get nothing

我試過WebDriverWait(browser, 30).until(EC.visibility_of_element_located((By.CLASS_NAME, "upload-file dropzone"))).send_keys(r"C:\\Users\\Dln\\Desktop\\wide.jpg")

但是我沒有上傳任何內容,它是可點擊的,它會打開一個窗口來從我的系統中選擇圖像,我嘗試在點擊上傳圖像按鈕后使用keyboard.type(path)但效率不高,所以我想知道其他方法。

這是按鈕的代碼

 <div class="fileinput-button"> <div class="file-input"> <div class="kv-upload-progress kv-hidden" style="display: none;"><div class="progress"> <div class="progress-bar bg-success progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;"> 0% </div> </div></div> <div class="clearfix"></div> <button type="button" tabindex="500" title="Abort ongoing upload" class="btn btn-default btn-secondary kv-hidden fileinput-cancel fileinput-cancel-button legitRipple"><i class="glyphicon glyphicon-ban-circle"></i> <span class="hidden-xs">Cancel</span></button> <div tabindex="500" class="btn btn-link btn-sm text-default font-weight-semibold btn-file legitRipple"><i class="icon-upload4 mr-2"></i> <span class="hidden-xs">Upload images</span><input type="file" name="file" id="upload-file-wysiwyg-btn" class="file-input file-input-custom form-control form-control-sm alpha-grey" multiple="multiple" data-browse-icon="<i class='icon-upload4 mr-2'></i>" data-browse-label="Upload images" data-show-caption="false" data-show-upload="false" data-browse-class="btn btn-link btn-sm text-default font-weight-semibold" data-remove-class="btn btn-light btn-sm" data-show-remove="false" data-show-preview="false" data-fouc=""></div> </div> </div>

使用文件路徑上傳的另一種有效方法

import os
driver.find_element_by_id("field_id").send_keys(os.getcwd()+"\wide.jpg")

有時元素可以是可見的,但還不能點擊。 嘗試使用

EC.element_to_be_clickable

作為等待條件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM