【发布时间】:2019-07-24 07:16:09
【问题描述】:
我正在尝试使用 python 自动化上传文件。 当我尝试执行下面的代码时,python selenium 会引发错误。 甚至我尝试等待 10 秒以避免同步问题。
driver.execute_script('window.open("https://ocr.space/" , "new window")')
Imagepath = r"C:\User\Desktop\banner.png"
field=driver.find_element_by_xpath('//input[@type="file"]')
field.send_keys(Imagepath)
NoSuchElementException:消息:没有这样的元素:无法定位 元素:{"method":"xpath","selector":"//input[@type="file"]"}
网址:
HTML sn-p:
<div class="span8">
<input type="file" id="imageFile" class="form-control choose valid">
</div>
【问题讨论】:
-
你为什么用
window.open()而不是标准方式打开网站?当您在新选项卡中打开站点时,您必须先切换到该选项卡,然后才能与之交互。这就是问题所在。 -
@JeffC 您需要询问 OP 的用例,而不是批评 OP 的方法。 OP 所遵循的方法可能依赖于我们不知道的其他因素。
-
@DebanjanB 我没有批评,我问了一个问题并解释了使用这种方法的问题......这解释了他收到的错误。
标签: python html selenium automation