将显示一个要求输入联系信息的弹出窗口。它不是iframe,或警报或基于Windows的弹出窗口。 URL甚至没有改变。在主页上,我点击“联系我们”,我弹出一个,看起来像一个表格。如何将驱动程序控制切换到它并发送输入联系信息?
任何帮助总是受到高度赞赏。
答案 0 :(得分:2)
我不确定您是否有特定问题,或者只是同步问题(本例将解决):
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10); // used for synchronization
driver.get("http://uptake.com/");
// Make sure page was loaded
WebElement contactUs = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText("Contact Us")));
contactUs.click();
// Wait for Contact Us div to become visible
// (by checking that title is displayed)
wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath("//h2[contains(text(), 'Contact us below.')]")));
// Start filling form
driver.findElement(By.name("name")).sendKeys("John Smith");
// ... rest of the fields
driver.findElement(By.name("message")).sendKeys("Hello!");
driver.findElement(By.xpath("//input[@value='Send']")).click();