無法在最後一步中單擊警報框中的「確定」。我也試過控制彈出窗口警報 - Selenium
public class MyFirst {
public static void main(String[] args) throws NoAlertPresentException,InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\kunal.bhaskar\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "https://www.goindigo.in";
driver.get(baseUrl);
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).clear();
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).sendKeys("Patna");
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[2]/input[1]")).sendKeys("Bengaluru");
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/input")).click();
Select adult = new Select(driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/div/div[1]/label[2]/select")));
adult.selectByVisibleText("2");
driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).clear();
driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).sendKeys("18 Oct 2017");
driver.findElement(By.xpath("//*[@id=\"return-date\"]")).clear();
driver.findElement(By.xpath("//*[@id=\"return-date\"]")).sendKeys("28 Oct 2017");
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/div/div/div/ul/li[1]/div/div[1]")).click();
driver.switchTo().alert().accept();
}
你得到了什麼錯誤? – nullpointer
我無法在最後一步點擊'確定'按鈕 – Kunal
org.openqa.selenium.NoAlertPresentException是錯誤 – iamsankalp89