标题:处理弹出框selenium代码,用于在同一个窗口//包预订中处理div pop;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Dubai {
public static void main(String[] args) throws Exception {
System.setProperty ("webdriver.chrome.driver",
"C:\\Users\\miyau\\Desktop\\test\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.thomascook.in/");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[text()='Not Now']")).click();
System.out.println("operation complit");
}
}
// snapshot of popup## Heading ##
你可以试试这段代码:
public class Dubai {
public static void main(String[] args) throws InterruptedException {
try {
public static void main(String[] args) throws Exception {
System.setProperty ("webdriver.chrome.driver",
"C:\\Users\\miyau\\Desktop\\test\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver,50 );
driver.manage().window().maximize();
Thread.sleep(500);
driver.get("http://www.thomascook.in/");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='__st_preview_frame_bpn']")));
System.out.println(driver.findElement(By.xpath("html/body/div[1]/div[2]/div[3]/span")).getText());
driver.findElement(By.id("__st_bpn_no")).click();
} catch (Exception e) {
e.printStackTrace();
}
}
}