在我的页面中有很多下拉框和文本字段。在 Eclipse IDE 中测试页面时,它显示了上述异常。我无法找到此异常的任何解决方案
这是我的代码:
public class QuoteNewEntry {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http:///";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testQuoteNewEntry() throws Exception {
driver.get(baseUrl + "");
System.out.println("The current Url: "+ driver.getCurrentUrl());
assertEquals("", driver.getTitle());
driver.findElement(By.id("RdbtnLight")).click();
driver.findElement(By.id("txtUserName")).clear();
driver.findElement(By.id("txtUserName")).sendKeys("tom");
driver.findElement(By.id("txtpassword")).clear();
driver.findElement(By.id("txtpassword")).sendKeys("tom");
driver.findElement(By.id("btnSubmit")).click();
assertEquals("", driver.getTitle());
driver.findElement(By.id("btnTrade")).click();
System.out.println("The current Url: "+ driver.getCurrentUrl());
assertEquals("", driver.getTitle());
driver.findElement(By.id("btnQuote")).click();
System.out.println("The current Url: "+ driver.getCurrentUrl());
assertEquals("Quote", driver.getTitle());
driver.findElement(By.id("ContentPlaceHolder1_btnNew")).click();
System.out.println("The current Url: "+ driver.getCurrentUrl());
new Select(driver.findElement(By.id("ContentPlaceHolder1_ddlLineOfBus"))).selectByVisibleText("FCL");
driver.findElement(By.id("ContentPlaceHolder1_txtCaptured")).clear();
driver.findElement(By.id("ContentPlaceHolder1_txtCaptured")).sendKeys("3");
driver.findElement(By.id("ContentPlaceHolder1_rbtn3rdParty")).click();
Thread.sleep(5000);
driver.findElement(By.id("ContentPlaceHolder1_txtTotalTransitDays")).clear();
driver.findElement(By.id("ContentPlaceHolder1_txtTotalTransitDays")).sendKeys("10");
driver.findElement(By.id("ContentPlaceHolder1_txtVoyageFrequency")).clear();
driver.findElement(By.id("ContentPlaceHolder1_txtVoyageFrequency")).sendKeys("weekly");
Thread.sleep(5000);
driver.findElement(By.id("ContentPlaceHolder1_txtExternal")).clear();
driver.findElement(By.id("ContentPlaceHolder1_txtExternal")).sendKeys("ex");
Thread.sleep(5000);
driver.findElement(By.id("ContentPlaceHolder1_btnSave")).click();
try{
driver.findElement(By.xpath("//input[@value = 'alert']")).click();
Thread.sleep(5000);
}
catch(WebDriverException we){
}
}
@After
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}