Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python selenium中使(style=";display:none";)元素在HTML中可见?_Python_Html_Selenium - Fatal编程技术网

如何在python selenium中使(style=";display:none";)元素在HTML中可见?

如何在python selenium中使(style=";display:none";)元素在HTML中可见?,python,html,selenium,Python,Html,Selenium,我试图在一个网站上使用python selenium上传文件,该网站的html文件字段如下所示: <div id="fallback" style="display: none;"> <input id="upload-input" type="file" name="file" multiple="multiple"> <div id="upload-progress" class="upload-progress"></div>

我试图在一个网站上使用python selenium上传文件,该网站的html文件字段如下所示:

 <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>
运行脚本后,脚本停止,而不上载文件,也不抛出任何错误


使用elem.is_display()后,我发现即使运行了上面的代码块,元素仍然没有显示。

包装
上有
样式
属性,但您试图将其从
中删除:

container=driver.find\u element\u by\u id(“回退”)
driver.execute_脚本(“参数[0].style.display='block';”,容器)
输入=驱动程序。按id查找元素(“上传输入”)
输入。发送密钥(路径到文件)
p.S.使用
style
属性是元素样式的实现细节。在这种情况下,您实际上只关心样式是什么,因此最好将其具体设置为您想要的样式,而不是删除实现它的特定方式。前者应该不那么易碎

p.p.S.您可能不需要将XPath用于像ID查找这样简单的事情。(ID在所有元素中都应该是唯一的;否则它们不是真正的ID。)

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']")