Python+selenium: Resolves an issue where uploading files <input type= ' file ' > tag properties are hidden by the visibility of CSS resulting in the inability to locate elements

Source: Internet
Author: User
Tags visibility

To upload a file, you need to find in the HTML <input type= "file"/> This tag, there is it can be used to upload files Send_keys, but here the The <input> element is hidden, causing it to not locate input

The HTML code is as follows, note Visibility:hidden, that this input element is hidden, in order to locate it must first remove the hidden attributes

General control element Display or hide is implemented using the Display property

Style.display = "None", indicating that the element is hidden;
Style.display = "Block",  indicating the display

But this is not using the Display property, but using the CSS's visibility property to implement,

Style.visibility= "hidden", which means the element is hidden;
style.visibility= "visible", indicating the element display;

So the use of JS to remove the hidden properties, began to want to only change the visibility property to visible, but has failed, and then simply the entire style attribute is removed not good, anyway, the purpose is to upload the file's properties to become visible, JS code as follows

JS = ' Document.queryselector ("#i_select_files >input"). style= "";  #js去掉上传文件 the attribute of the "input" element to make it visible driver.execute_script (JS)

After removing the hide, the effect is as follows, you can see a "Select File" button

Python+selenium: Resolves an issue where uploading files <input type= ' file ' > tag properties are hidden by the visibility of CSS resulting in the inability to locate elements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.