我想使用 JavaScript 按钮上传带有 selenium 的文件
HTML 代码:
<div class="option optionFile">
<label class="editionFieldMandatory" for="file">File</label>
<input id="file_input" class="file" width="120" type="file" height="30" name="file_input" style="display: none;">
<object id="file_inputUploader" width="120" height="30" type="application/x-shockwave-flash" data="/scripts/external_api/uploadify.swf" style="visibility: visible;">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="allowScriptAccess" value="sameDomain">
<param name="flashvars" value="uploadifyID=file_input&pagepath=/content/&buttonText=Browse&script=/utils/upload_library.php?session_name=j2cnrk8ehssuhhi78gq2pdqoa1&folder=/var/www/BO/IHM/resources/documents/help_manuals&width=120&height=30&wmode=transparent&method=POST&queueSizeLimit=999&simUploadLimit=1&hideButton=true&fileDesc=Documents&fileExt=*.aac; *.aif; *.aiff; *.avi; *.bmp; *.conf; *.csv; *.doc; *.docx; *.dot; *.dotm; *.dotx; *.exe; *.flac; *.gif; *.htm; *.html; *.jpeg; *.jpg; *.log; *.lpcm; *.m2t; *.m2ts; *.mhtml; *.mid; *.mka; *.mkv; *.mov; *.mp3; *.mp4; *.mpeg; *.mpg; *.msi; *.ogg; *.pcm; *.pdf; *.png; *.pot; *.pps; *.ppt; *.pub; *.rar; *.tgz; *.tp; *.ts; *.txt; *.vdx; *.vob; *.vsd; *.vss; *.vst; *.vsx; *.vtx; *.wav; *.wma; *.wmv9; *.xls; *.xlsb; *.xlsm; *.xlsx; *.xml; *.zip&auto=true&sizeLimit=15728640&fileDataName=Filedata">
</object>
<div id="file_inputQueue" class="uploadifyQueue"></div>
</div>
</div>
我有一个测试,但它失败了:
WebElement elem = driver.findElement(By.xpath("//input[@id='file_input']"));
elem.sendKeys("C:\test");
坦克为您提供帮助。