我正在尝试使用带有Java的selenium来自动执行页面,该代码似乎可以正常工作到一定程度,但是之后没有任何效果。
请在下面找到代码:
try {
driver.manage().window().maximize();
WebElement element1 = driver.findElement(By.cssSelector("table[id='itm_0'] tbody tr td a[class='LVL0']"));
element1.click();
element1 = driver.findElement(By.xpath("//*[@id=\"varTableIdResult\"]/tbody/tr/td[2]"));
element1.click();
element1 = driver.findElement(By.id("expand"));
element1.click();
Thread.sleep(2000);
System.out.println("Initiated successfully");
String parentWindow= driver.getWindowHandle();
System.out.println("the window handle name is::"+parentWindow);
driver.findElement(By.xpath("//*[@id=\"DetailsForm\"]/table/tbody/tr/td[2]/a/img")).click();
//Code works till this point, but next steps are not executed
driver.switchTo().window(parentWindow);
System.out.println("Before PDF Save");
PDFSave ();
System.out.println("Before PDF Save");
}
public void PDFSave() throws InterruptedException {
// -- AutoIT Code needed for PDF Save
try {
Process process = Runtime.getRuntime()
.exec("C:\\LogFiles\\PDFSave.exe");
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
}
控制台输出:
Started InternetExplorerDriver server (32-bit)
3.9.0.0
launching IE Browser
Initiated successfully
the window handle name is::c0a1854c-4ef4-4c29-9b7d-6bf84a539053
关于如何解决此问题的任何建议? 如何将控件带回Java代码?