0

I'm trying to upload images through Python Selenium, it worked before but now they random generate the ID of button. I've tryed with different css path,xpath to make it working but i don't have any other ideea.

HTML

<div id="ImageUpload" class="form-section" style="position: relative;">
            <div class="file-input-wrapper">
                <button id="ImageUploadButton" type="button" class="button-update-cancel short file-upload-button ">
                            Select Images</button>
                        <input type="hidden" name="file" id="FileUploadInput">
                    <span class="field-message" data-for="FileUploadInput"></span>

                <p class="message"><strong>Get at least twice the number of replies by uploading images</strong><br>Max 10 images. File size can be 15 MB per image with max dimension 6000x4000. For bitmap(.bmp) images, max file size is 4MB.</p>

                <p class="file-input-current file-uploading">Uploading...</p>
                <ol id="UploadingImages"></ol>

                <p class="image-select">Select a "MAIN" image :</p>
                <ol id="UploadedImages">
                    </ol>
            </div>
            <input type="hidden" name="images">
            <div id="flash_19b01203e1o5npfd1nulhk11f293_container" class="moxie-shim moxie-shim-flash" style="position: absolute; top: 5px; left: 0px; width: 99px; height: 21px; overflow: hidden;"><object id="flash_19b01203e1o5npfd1nulhk11f293" type="application/x-shockwave-flash" data="Moxie.cdn.swf" width="100%" height="100%" style="outline:0"><param name="movie" value="Moxie.cdn.swf"><param name="flashvars" value="uid=flash_19b01203e1o5npfd1nulhk11f293&amp;target=moxie.core.EventTarget.instance.dispatchEvent"><param name="wmode" value="transparent"><param name="allowscriptaccess" value="always"></object></div></div>
            <object id="flash_19b01203e1o5npfd1nulhk11f293" type="application/x-shockwave-flash" data="Moxie.cdn.swf" width="100%" height="100%" style="outline:0"><param name="movie" value="Moxie.cdn.swf"><param name="flashvars" value="uid=flash_19b01203e1o5npfd1nulhk11f293&amp;target=moxie.core.EventTarget.instance.dispatchEvent"><param name="wmode" value="transparent"><param name="allowscriptaccess" value="always"></object>

And the python code

 ### IMAGE UPLOAD ###
img_path="C:\\1.jpg"
s = win32com.client.Dispatch('WScript.Shell')
time.sleep(3)
browser.find_element_by_id('#flash_19b01203e1o5npfd1nulhk11f293').click()
time.sleep(2)
s.SendKeys(img_path, 0)
time.sleep(2)
s.SendKeys("{ENTER}", 0)

Any suggestions?

2
  • I can't see where you're clicking on the button. In which step of your script does it fail?1. Using Selenium to click on the flash element? 2. Using WScript.Shell to type in the file path? or 3. Using WScript.Shell to hit enter and presumably submit the form? Commented Jan 6, 2015 at 17:43
  • I used chromedriver and it's work to click on flash element. The problem it's the object id it's random generated and I get always NoSuchElement. <object id="flash_19b01203e1o5npfd1nulhk11f293" type="application/x-shockwave-flash" data="Moxie.cdn.swf" width="100%" height="100%" style="outline:0"> I've asked if theres any way to click on this button if the id it's random generated. Commented Jan 6, 2015 at 17:46

1 Answer 1

1

If the id is always changing, look for a different way of identifying the element.

Is the element always the first flash object inside the <div id="ImageUpload" element? If so, try this:

browser.find_element_by_xpath("//div[@id='ImageUpload']//object[@type='application/x-shockwave-flash']").click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.