【问题标题】:Unable to upload image using Selenium Java无法使用 Selenium Java 上传图像
【发布时间】:2022-01-25 05:42:59
【问题描述】:

我需要使用 Selenium Web 驱动程序和 Java 上传图像。 我尝试了以下方法:

  1. sendkeys() : 它不工作 [xpath used: //input[@id='brandingContent_AddImage']]
  2. 机器人类:仅在本地工作,但在远程和并行执行中停止工作。
  3. Sikuli :仅在测试执行屏幕处于焦点时工作。在并行执行中不起作用。
  4. AutoIT:尚未尝试。

需要一种能够成功上传图像并且可以并行执行的方式。 提前谢谢..!!

以下是 HTML 片段:HTML IMAGE

<div class="fileinput fileinput-new col-md-4 pl-1 " data-provides="fileinput">                            <div class="w-100 float-left">                                <div class="ctn_img_upload pull-left" id="uploadView_brandingContent_AddImage" xpath="1">                                    <div class="ad_file">                                        <span class="flaticon-plus"></span>                                        <input type="hidden" value="" name=""><input autocomplete="off" type="button" data-minsize="300x600" data-c="" data-placeholder="brandingContent_AddImage" id="brandingContent_AddImage" class="browse-img fileupload-skin" onclick="brandingViewGenerator.uploadImage(event)" style="position: absolute;top: 0;left: -8px;right: 0;bottom: 0;width: 74px;height: 66px;">                                        <label class="fileupload-skin-label" for="editpanel_native_1" id="">Upload</label>                                    </div>                                </div>                                <div class="edit-image" id="branding_image_preview_brandingContent_AddImage" style="display:none">                                    <img id="imageBlock_brandingContent_AddImage" src="">                                    <input class="delete1 bg-blue-flamingo" type="button" onclick="brandingViewGenerator.editImage(event)" id="edit_brandingContent_AddImage">                                   <input class="update bg-blue" type="button" id="upload_brandingContent_AddImage" data-minsize="300x600" onclick="brandingViewGenerator.uploadImage(event)">                                </div>                            </div>                            <br clear="all">                            <input type="hidden" name="centerStrech" value="center">                        </div>

【问题讨论】:

    标签: java selenium file-upload webdriver


    【解决方案1】:

    最简单的方法是,如果您在 HTMLDOM 中看到//input[@type='file'],那么您可以将它与

    一起使用
    driver.findElement(by.xpath("//input[@type='file']")).sendKeys("full path of the file which is to be uploaded");
    

    【讨论】:

    • 由于这个元素的类型是 'button',sendkeys 不起作用。
    • 你在整个 HTMLDOM 中看到 //input[@type='file'] 了吗?
    • 不。我还添加了 Html sn-p 的图像
    • 是的,但是 sn-p 没有完整的 HTML,您可以使用浏览器检查检查 HTMLDOM 吗?
    猜你喜欢
    • 1970-01-01
    • 2018-12-22
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多