Last active
February 22, 2022 02:28
-
-
Save florentbr/d7bee068932bdf6e00af3b9f01af9af6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# disable the file picker | |
driver.execute_script(""" | |
HTMLInputElement.prototype.click = function () { | |
if (this.type !== 'file') { | |
HTMLElement.prototype.click.call(this); | |
} | |
else if (!this.parentNode) { | |
this.style.display = 'none'; | |
this.ownerDocument.documentElement.appendChild(this); | |
this.addEventListener('change', () => this.remove()); | |
} | |
} | |
""") | |
# perform the click | |
driver.find_element_by_xpath('//button[normalize-space()="Upload"]')\ | |
.click() | |
# assign the file to the <input type="file"> | |
driver.find_element_by_css_selector('input[type=file]')\ | |
.send_keys(r'c:/myimage.png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment