【发布时间】:2012-09-03 23:45:02
【问题描述】:
我正在尝试在 Google Drive 中自动上传文件功能。
用于传递参数的元素被隐藏,高度为0px。
任何用户操作都不会使该元素可见。因此,我需要解决方法以在元素不可见时单击它。
<input type="file" style="height: 0px; visibility: hidden; position: absolute; width: 340px; font-size: inherit;" multiple=""/>
上述元素的 xpath 是 -
//*[@class='goog-menu goog-menu-vertical uploadmenu density-tiny']/input
我正在使用
WebDriver.findElement(By.xpath(<xpath>).sendKeys(<uploadFile>)
例外 -
org.openqa.selenium.ElementNotVisibleException
- 元素当前不可见,因此可能无法与之交互。
我尝试过使用 JavascriptExecutor。但是找不到确切的语法。
【问题讨论】:
-
看一下 HTML,Google Drive 只是一个表单吗?如果是这样,请不要使用 Selenium,只需编写一个脚本来发布包含您指定数据的表单。
标签: selenium webdriver hidden-field