在我的情況下,在方法下工作。 我現在使用Windows,但在編寫一些測試後,要將它轉移到* nix環境。一些很酷的傢伙說道路必須是抽象的。Java。硒。上傳另一個文件
driver.findElement(By.id("admin_offer_kind_logo")).sendKeys("C:\\Path\\To\\File");
但我嘗試:
driver.findElement(By.id("admin_offer_kind_logo")).sendKeys(System.getProperty("user.dir")+"\\src\\test\\resources\\Koala.jpg");
或
driver.findElement(By.id("admin_offer_kind_logo")).sendKeys(System.getProperty("user.dir")+"/src/test/resources/Koala.jpg");
它並不想上傳該死的文件。
@Test
public void FileFinding() {
String file = System.getProperty("user.dir");
System.out.print("FilePath: ");
System.out.println(file);
}
以上代碼打印:FilePath: C:\SeleniumTests\FirstWebDriverTest
到我的項目文件的完整路徑是:
C:\SeleniumTests\FirstWebDriverTest\src\test\resources\Koala.jpg