我使用Selenium 2.x WebDriver進行java項目的自動化。 當自動化進行時,它會到達一個頁面,當點擊一個提交按鈕時會出現一個「彈出窗口」,並且自動化不能繼續進行。Selenium自動化不適用於彈出窗口
代碼
public void writeSite(WebDriver driver, ZoneTest zone) throws BiffException, InterruptedException, IOException
//Creates a new zone for testing
General.elementClick_xpath(driver, Locators.siteMenuDropBoxXpath);
General.waitToLoad(General.WAIT_MIN);
General.elementClick_xpath(driver, Locators.viewSitesButtonXpath);
General.elementClick_xpath(driver, Locators.viewDataPointDetailsXpath);
General.waitToLoad(General.WAIT_AVG);
General.elementClick_xpath(driver, Locators.addZoneXpath);
General.waitToLoad(General.WAIT_AVG);
General.inputTextFieldEnter_Id(driver, "name", zone.zoneName);
General.inputTextFieldEnter_Id(driver, "description",zone.zoneDescription);
General.inputTextFieldEnter_Id(driver, "urlExtension", zone.urlExtension);
General.inputTextFieldEnter_Id(driver, "timeSpentThreshold", zone.thresholdTime);
General.inputTextFieldEnter_Id(driver, "tuningNumber", zone.tuningNumber);
**General.elementClick_xpath(driver, Locators.createZoneSubmitXpath);**
//Here a new pop up window apppears. And the following codes 3 lines doesnt work.
General.inputTextFieldEnter_Id(driver, "active", zone.act);
General.inputTextFieldEnter_Id(driver, "userid", zone.uid);
General.elementClick_xpath(driver, Locators.SubmitXpath)
}
public class General
{
public static final long WAIT_MICRO = 500;
public static final long WAIT_MIN = 2000;
public static final long WAIT_AVG = 5000;
public static final long WAIT_MAX = 5500;
public static String baseUrl ="";
//Method to wait
public static void waitToLoad(long milliSeconds) throws InterruptedException {
Thread.sleep(milliSeconds);
}
// Method to load the Url taken from the config.property file
public static void loadBaseUrl(WebDriver driver){
baseUrl = PropertyUtility.getProperty("Baseurl");
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
public static void inputTextFieldEnter_xpath(WebDriver driver, String LocatorId, String ValueToBeEntered) throws InterruptedException {
System.out.println("Log in user name_inputTextField_outside if: "+ ValueToBeEntered);
WebElement inputTextField = driver.findElement(By.xpath(LocatorId));
General.waitUntilElementVisible(driver, LocatorId);
inputFieldClear_xpath(driver,LocatorId);
inputTextField.sendKeys(ValueToBeEntered);
}
如何切換視圖到新的彈出窗口?
不知道爲什麼4個upvotes這個簡單回答的問題! – 2014-09-29 12:05:09
[如何處理在使用Java的硒webdriver彈出]可能重複(http://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java) – 2014-09-29 12:05:27
@Vignesh Paramasivam和3 upvotes和2收益的問題%)似乎這些傢伙是朋友:D – 2014-09-30 10:53:14