在没有移动任何其他区域的情况下正确运行以下脚本,但如果执行任何操作,我的意思是移动到任何其他区域,此时我的下载文件代码不起作用。
是与焦点有关的问题还是需要一些改变。使用 firefox 21 版本浏览器和 selenium 2.33。请建议。
这是代码:
package mypackage;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.junit.Before;
import org.junit.Test;
import Data.Function;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.junit.After;
public class Report extends Function {
Object Open_a_popup_window;
String Positioned_Popup ;
Object JavaScript_Popup_Windows ;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "my url";
}
@Test
public void Report1() throws Exception {
Function object = new Function();
object.Login();
/* Enter Report Details */
driver.get(baseUrl + "//");
driver.get(baseUrl + "//");
/*Run*/
driver.findElement(By.xpath("")).click();
Thread.sleep(30000);
WebElement Action = driver.findElement(By.xpath(""));
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
((JavascriptExecutor) driver).executeScript("window.focus();");}
String linktxt = Action.getText();
if (linktxt.equalsIgnoreCase("Record not found.")) {
System.out.println("Report contains No Data:");
}
if (linktxt.equalsIgnoreCase("FAILED")) {
System.out.println("Report failed");
} else {
driver.findElement(By.xpath("/img")).click();
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(10000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(10000);
System.out.println("Report Passed");
}
}
}
@After
public void teardown() {
driver.close();
//System.exit(0);
}
}