Selenium Failing to Upload Picture

28 views Asked by At

I'm facing an issue when uploading a picture through selenium. The HTML code:

<form enctype='multipart/form-data' method='post' action='./upload_ss.cgi'>
                        <h1>Upload a new photo here</h1>
                        <br>
                        Allowed files:<br>
                        <ul>
                            <li>Format: PNG</li>
                            <li>Maximum resolution: 1366 x 768 </li>
                        </ul>
                        <input type='hidden' name='csrf_token' value='qxASP72Kg4RFVpSHyCt0_zFA8CYkSB9Rc89bVx8mFHc.'>
                        <input type='file' name='file' accept='image/*' style='width:100%'>
                        <br>
                        <br>
                        <input type='submit' name='file' value='Upload File' style='width:100%'>
                    </form>
                </section>
            </div>

my code:

        self.form_screen = self.wait.until(EC.presence_of_element_located((By.XPATH,'//form[@action="./upload_ss.cgi"]')))

        #Inserting the picture
        self.change_picture = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[name="file"][accept="image/*"]')))
        self.change_picture.send_keys(picture1_path)
        time.sleep(4)
        self.button_picture = self.wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="content"]/section[2]/form/input[3]')))
        self.button_picture.click()
        self.wait.until(EC.staleness_of(self.form_screen))

The code works until the send keys part, but when the button is pressed, it goes to "page can't be reached". enter image description here

enter image description here

I have researched extensively but i coun't find any related issue. Any thoughts?

Thanks all!

Tried several ways to upload it, but none worked. The code works normally for all the other functions, just encountering issues for the upload.

0

There are 0 answers