python - 使用 Selenium-Python 通过 WebDriver 上传图像
问题描述
所以我正在制作这个 python 机器人来为 1 个转售网站自动发布广告。
而且我碰壁了,机器人登录做的一切都很完美,但是当涉及到图像上传时,我无法让它工作。
这是我用于图片上传的部分:
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/
这就是网站的图片上传部分的样子 ->
这是图片上传部分的 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>
解决方案
推荐阅读
- asp.net-mvc - 剑道导出excel缺少$符号
- ios - 如何使用swift通过ios应用程序中的音频插孔获取数据?
- c# - 在 MS Teams 机器人中提交后 AdaptiveCard 清除
- javascript - 条件对象作为数组值
- c++ - 错误:输入'class Eigen::Tensor
' 给 'delete' 的参数,预期的指针 - php - Firebase 推送通知不起作用获取令牌编号但仍然不起作用
- android - 签名的 apk 失败并出现错误 FileUsesReservedNameException
- excel - 插入列后如何更新单元格中的引用
- vue.js - 如何使用 VueCli 3 重命名 index.html 中的 app.js 文件
- qt5 - 对象之间的 Qt 信号导致锁定