このコードが機能していることを確認してください。sendkeysで正しいファイルパスを使用してください
driver.get("http://www.freepdfconvert.com/");
driver.findElement(By.id("UploadedFile")).sendKeys("C:\\Users\\username\\Downloads\\HP1.pdf");
try {
Thread.sleep(4000);
}
catch (Exception e) {}
driver.findElement(By.name("pdfsubmit")).click();
}
また
driver.findElement(By.id("uploadField")).sendKeys("C:/xyz.txt");
driver.findElement(By.name("uploadButton")).click();
name または Xpath を使用し、次にチェックします。
編集
はい、すべてのブラウザで実行できますが、IE と chrome では小さなコードを追加する必要があります。いいえ:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
クロム
File file = new File("E://chromedriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();`