以下代码完美地下载PDF。现在我想将这个PDF内容转换为文本文件。请帮助。我通过护目镜尝试了很多代码,但都没有工作。Selenium Webdriver - 帮助PDF到文本转换
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@Test
public class PDF_Download_without_popup {
WebDriver driver;
@BeforeTest
public void StartBrowser() {
//Create object of FirefoxProfile in built class to access Its properties.
FirefoxProfile fprofile = new FirefoxProfile();
//Set Location to store files after downloading.
fprofile.setPreference("browser.download.dir", "c:\\WebDriverdownloads");
fprofile.setPreference("browser.download.folderList", 2);
//Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"//MIME types Of MS Excel File.
+ "application/pdf;" //MIME types Of PDF File.
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" //MIME types Of MS doc File.
+ "text/plain;" //MIME types Of text File.
+ "text/csv"); //MIME types Of CSV File.
fprofile.setPreference("browser.download.manager.showWhenStarting", false);
fprofile.setPreference("pdfjs.disabled", true);
//Pass fprofile parameter In webdriver to use preferences to download file.
driver = new FirefoxDriver(fprofile);
}
public void OpenURL() throws InterruptedException{
driver.get("http://www.bell.ca/");
driver.manage().window().maximize();
Thread.sleep(30000);
driver.findElement(By.xpath(".//*[@id='demoLoginLinkJs']/span[1]")).click();
driver.findElement(By.xpath(".//*[@id='USER']")).sendKeys("bell_56789");
driver.findElement(By.xpath(".//*[@id='PASSWORD']")).sendKeys("sunday21");
driver.findElement(By.xpath(".//*[@id='demoLoginJs']")).click();
driver.findElement(By.xpath("//span[contains(text(),'View current bill')]")).click();
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='btnDownloadBill']")).click();
String tmp= driver.getCurrentUrl().toString();
System.out.println(tmp);
Thread.sleep(50000);
}
@AfterTest
public void CloseBrowser() {
driver.quit();
}
}
你得到了什么错误? –
请将Selenium webdriver –
下载的PDF格式的PDF转换为文本的代码或链接,请不要将PDF代码处理成PDF ..请帮助 –