我正在使用硒自動化,我無法上傳具有相對路徑的文件,請參閱下面的代碼。如何在selenium webdriver中使用相對路徑上傳文件
driver.findElement(By.xpath("//span[text()='Theme']")).click();
File filepath=new File("\ntwinelogin.jpg");
WebElement fileobj = driver.findElement(By.name("toplogoupload"));
fileobj.sendKeys("\ntwinelogin.jpg");
String Filepath=filepath.getAbsolutePath();
Filepath.trim();
你應該得到的絕對路徑,並加入與您的文件名,然後將它傳遞。 –
similer to https://stackoverflow.com/questions/16896685/how-to-upload-file-using-selenium-webdriver-in-java –