使用Selenium-Python使用WebDriver上传图像

时间:2018-12-31 22:45:28

标签: python selenium selenium-webdriver webdriver

因此,我正在将此python机器人制作为1个转售网站的自动AD发布。

我碰壁了,机器人登录程序可以完美地完成所有工作,但是当涉及到图像上传时,我无法正常工作。

这是我用于图像上传的部分:

img_path = '/home/djurovic/Desktop/test/image.png'
imageUploadXpath = '//button[@id="ImageUploadButton"]'
imageUploadElement = WebDriverWait(browser, timeout).until(lambda browser: browser.find_element_by_xpath(imageUploadXpath))
imageUploadElement.send_keys(img_path)

整个脚本有很多代码,所以我不想在这个问题上花很多时间,这是困扰我的唯一部分...

这是我要自动化的网站:https://www.kijiji.ca/

这是网站的图像上传部分的外观->

enter image description here

这是图片上传部分的html一侧:

<li class="jsonly">
    <div id="MediaImageUpload" class="clearfix form-section placeholders">
        <p class="images-title">Add at least one photo to complete your ad.</p>
        <div class="images-content">
            <h3>Add photos to attract interest to your ad</h3>
            <div class="images-content-secondary">
                <p>Include pictures with different angles and details. 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>
                <p>Drag and drop to change the order of your pictures.</p>
            </div>
        </div>
        <ol id="MediaUploadedImages">
            </ol>

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

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

            <div class="imageUploadButtonWrapper">
                <button id="ImageUploadButton" type="button" class="button-update-cancel short file-upload-button">
                    Select Images</button>
            </div>
        </div>
    </div>
</li>

0 个答案:

没有答案