How can make (style ="display: none;") element visible in HTML in python selenium?
The style
attribute is on the wrapping <div>
, but you're trying to remove it from the <input>
:
container = driver.find_element_by_id("fallback")
driver.execute_script("arguments[0].style.display = 'block';", container)
input = driver.find_element_by_id("upload-input")
input.send_keys(path_to_file)
P.S. The use of the style
attribute is an implementation detail of how an element is styled. In this case, you really only care about what the style is, so better to specifically set it to what you want rather than delete a particular way of implementing it. The former should be less brittle.
P.P.S. You probably don't need to use XPath for something as simple as a lookup by ID. (IDs should be unique across all elements; otherwise they're not really IDs.)
Related videos on Youtube
Comments
-
alter123 almost 2 years
I'm trying to upload file using python selenium on a website whose file field in html looks like this:
<div id="fallback" style="display: none;"> <input id="upload-input" type="file" name="file" multiple="multiple"> <div id="upload-progress" class="upload-progress"></div> </div>
I'm trying to make element visible via following code:
elem = driver.find_element_by_xpath("//input[@id='upload-input']") driver.execute_script("arguments[0].removeAttribute('style')", elem) elem = driver.find_element_by_xpath("//input[@id='upload-input']")
After running the script, script stops without uploading the file and without throwing any error.
After using elem.is_displayed(), I've found the element is still not displayed even after running the above block of code.
-
undetected Selenium about 6 yearsPossible duplicate of How can i upload files on dropzone.js with style="display: none;" using Selenium?
-