0
我想上传一个文件,但没有更迭,我发现这个例子:测试自动化。文件上传Java和硒
WebElement element = getSupport().getDriver().findElement(By.xpath(".//input[@type='file']"));
element.sendKeys("D:/Profiles/user/workspace/copla-selenium/src/test/resources/datasets/default/test-image.jpg");
但我得到这个错误:
2015-02-23 17:32:59 ERROR root:97 - Test failed org.openqa.selenium.WebDriverException: unknown error: cannot focus element
任何想法?谢谢!
应该有一个'input'元素负责上传字段。 – alecxe 2015-02-23 16:47:43
我真的不知道你是什么意思,在这个例子中就像我做的那样:[example](http://stackoverflow.com/questions/9431978/one-solution-for-file-upload-using-selenium- webdriver-with-java) – Anna 2015-02-23 16:51:48
查看在那个线程中使用的xpath指向一个'input'元素 - 你指向一个'a'元素。这可能是这里的问题。 – alecxe 2015-02-23 16:53:40