Uploading images with WebDriver using Selenium-Python












1















So I'm making this python bot to automatized AD posting for 1 reselling site.



And I've hit a wall, the bot logins does everything perfect but when it comes to image upload I can't get it to work.



This is my part that I used for image upload:



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)


The whole script has a lot of code so I don't want go over the top with this question, this is the only part that is bugging me...



This is the site I'm trying to automatized : https://www.kijiji.ca/



This is how image upload section of the website looks like ->



enter image description here



Here is the html side of the image upload section:






<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>












share|improve this question

























  • can you add the html of the button and the input you are sending the path to?

    – Moshe Slavin
    Jan 1 at 8:53











  • @MosheSlavin I've edited and added the HTML for the image upload section.

    – Stefan
    Jan 1 at 10:59











  • Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

    – Moshe Slavin
    Jan 1 at 11:01











  • Okay, will do that right now...

    – Stefan
    Jan 1 at 11:02











  • @MosheSlavin I've added the html

    – Stefan
    Jan 1 at 11:04
















1















So I'm making this python bot to automatized AD posting for 1 reselling site.



And I've hit a wall, the bot logins does everything perfect but when it comes to image upload I can't get it to work.



This is my part that I used for image upload:



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)


The whole script has a lot of code so I don't want go over the top with this question, this is the only part that is bugging me...



This is the site I'm trying to automatized : https://www.kijiji.ca/



This is how image upload section of the website looks like ->



enter image description here



Here is the html side of the image upload section:






<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>












share|improve this question

























  • can you add the html of the button and the input you are sending the path to?

    – Moshe Slavin
    Jan 1 at 8:53











  • @MosheSlavin I've edited and added the HTML for the image upload section.

    – Stefan
    Jan 1 at 10:59











  • Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

    – Moshe Slavin
    Jan 1 at 11:01











  • Okay, will do that right now...

    – Stefan
    Jan 1 at 11:02











  • @MosheSlavin I've added the html

    – Stefan
    Jan 1 at 11:04














1












1








1


0






So I'm making this python bot to automatized AD posting for 1 reselling site.



And I've hit a wall, the bot logins does everything perfect but when it comes to image upload I can't get it to work.



This is my part that I used for image upload:



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)


The whole script has a lot of code so I don't want go over the top with this question, this is the only part that is bugging me...



This is the site I'm trying to automatized : https://www.kijiji.ca/



This is how image upload section of the website looks like ->



enter image description here



Here is the html side of the image upload section:






<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>












share|improve this question
















So I'm making this python bot to automatized AD posting for 1 reselling site.



And I've hit a wall, the bot logins does everything perfect but when it comes to image upload I can't get it to work.



This is my part that I used for image upload:



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)


The whole script has a lot of code so I don't want go over the top with this question, this is the only part that is bugging me...



This is the site I'm trying to automatized : https://www.kijiji.ca/



This is how image upload section of the website looks like ->



enter image description here



Here is the html side of the image upload section:






<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>








<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>





<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>






python selenium selenium-webdriver webdriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 11:39









Gama11

11.8k52349




11.8k52349










asked Dec 31 '18 at 22:45









StefanStefan

649




649













  • can you add the html of the button and the input you are sending the path to?

    – Moshe Slavin
    Jan 1 at 8:53











  • @MosheSlavin I've edited and added the HTML for the image upload section.

    – Stefan
    Jan 1 at 10:59











  • Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

    – Moshe Slavin
    Jan 1 at 11:01











  • Okay, will do that right now...

    – Stefan
    Jan 1 at 11:02











  • @MosheSlavin I've added the html

    – Stefan
    Jan 1 at 11:04



















  • can you add the html of the button and the input you are sending the path to?

    – Moshe Slavin
    Jan 1 at 8:53











  • @MosheSlavin I've edited and added the HTML for the image upload section.

    – Stefan
    Jan 1 at 10:59











  • Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

    – Moshe Slavin
    Jan 1 at 11:01











  • Okay, will do that right now...

    – Stefan
    Jan 1 at 11:02











  • @MosheSlavin I've added the html

    – Stefan
    Jan 1 at 11:04

















can you add the html of the button and the input you are sending the path to?

– Moshe Slavin
Jan 1 at 8:53





can you add the html of the button and the input you are sending the path to?

– Moshe Slavin
Jan 1 at 8:53













@MosheSlavin I've edited and added the HTML for the image upload section.

– Stefan
Jan 1 at 10:59





@MosheSlavin I've edited and added the HTML for the image upload section.

– Stefan
Jan 1 at 10:59













Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

– Moshe Slavin
Jan 1 at 11:01





Thanks, but can you add the actual HTML code? not just the pic... I'm asking this because there is no input tag here...

– Moshe Slavin
Jan 1 at 11:01













Okay, will do that right now...

– Stefan
Jan 1 at 11:02





Okay, will do that right now...

– Stefan
Jan 1 at 11:02













@MosheSlavin I've added the html

– Stefan
Jan 1 at 11:04





@MosheSlavin I've added the html

– Stefan
Jan 1 at 11:04












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991949%2fuploading-images-with-webdriver-using-selenium-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991949%2fuploading-images-with-webdriver-using-selenium-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory