gpt4 book ai didi

java - Selenium 自动化不适用于弹出窗口

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:06 25 4
gpt4 key购买 nike

我正在使用 Selenium 2.x WebDriver 实现 java 项目的自动化。当自动化继续进行时,它会到达一个页面,在该页面中,当单击提交按钮时,会出现一个“弹出窗口”,并且无法继续进行自动化。

代码

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);
}

如何将 View 切换到新的弹出窗口?

最佳答案

如果想在弹窗中进行操作,这里是WebDriver选择弹窗的逻辑。

driver.switchTo().window("<window name>");

关于java - Selenium 自动化不适用于弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com