我正在尝试在 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>)
异常(exception) -
org.openqa.selenium.ElementNotVisibleException
我尝试过使用 JavascriptExecutor。但无法找到确切的语法。
最佳答案
简单的解决方案:
WebElement tmpElement = driver.finElement(ElementLocator);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", tmpElement);
关于Selenium Webdriver - 点击隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12363038/