我正在尝试使用 webdriver 自动上传文件,我的 HTML 是
它是文件类型。
使用 Firebug 我得到了 id,它对于文本框和按钮是相同的。
通过使用此命令 getWebDriverObj().findElement(By.id("fileupload")).sendKeys("code.txt");我无法获取结果。
有没有人遇到过这种情况,如果有,请帮帮我。
谢谢
拉古拉姆。
最佳答案
Autois 仅适用于 Windows。
这是一个更强大的解决方案:
为此,您将找到实际输入框的“id”(提供文件路径的位置),然后使用以下命令:
driver.findElement(By.id("upload")).sendKeys("/path/to/the/file"); driver.findElement(By.id("upload_button")).click();
如果您使用的是 WebDriverBackedSelenium,您可以使用:
selenium.type("locator", "/path/to/the/file");
selenium.click("upload_button");
关于file - 如何使用 webdriver 自动上传文件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10444089/