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