Tes关闭弹出窗口后失败

时间:2016-11-25 08:11:25

标签: selenium selenium-webdriver popup window

我正在我的项目中使用页面工厂实现POM 我正面临一个问题

此页面内的应用程序中有一个页面"文件夹"链接存在,当我点击这个弹出窗口打开 我必须搜索文件夹并选择此项(输入foldername,选择单选按钮,单击go按钮) 这是我能够做到的,但是当我在填充此弹出窗口的所有数据后点击Go按钮时 这个弹出窗口被关闭并且选定的数据显示在主页面上但是在此之后我的下一个命令没有被执行,就像填充下一个文件中的值一样。

我在我的测试页面中调用下面的方法

public void TabHandles() throws Throwable {

    String currentWindowHandle = driver.getWindowHandle();

    //Get the list of all window handles
    ArrayList<String> windowHandles = new ArrayList<String>(driver.getWindowHandles());

    for (String window:windowHandles){

    //if it contains the current window we want to eliminate that from switchTo();
    if (window != currentWindowHandle)
    {
    //Now switchTo new Tab.
    driver.switchTo().window(window);
    //Do whatever you want to do here.
    //driver.close();


    driver.switchTo().defaultContent();
    }

public ProfilePage CompleteUccForm() throws Throwable {

    test.log(LogStatus.INFO, "Cliking in the UCC Tab");
    //upload.click();


    ucc.click();

    folder.click();


    //newttab();

    tabHandles();

    foldertext.sendKeys("Applesamsung");
    foldergo.click();
    folderradio.click();
    folderselect.click();

    // maintabttab();

    realestatecheck.click();
    contactname.sendKeys("deepak");
    relation.sendKeys("Lessee/Lessor");

我的测试用例失败了。带有以下错误---

FAILED: CompleteUccForm-
org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed.
Command duration or timeout: 31 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'DS-E0699598D816', ip: '10.97.222.20', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=37.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6ca9a623-ea39-4c16-a7dd-e1b3f80afd04
*** Element info: {Using=xpath, value=//*[@id='ctrlLien_lienHeadercontrol_chkFixture']}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

请回复我很久以来就遇到了这个问题

2 个答案:

答案 0 :(得分:1)

关闭弹出窗口后,您需要再次运行SwitchTo命令切换到您需要的任何窗口,然后Web驱动程序将能够找到元素并执行您需要的操作。

P.S:在弹出窗口出现之前,将Window Id存储在某个字符串变量中,一旦弹出窗口关闭,它将很容易再次切换回来。

答案 1 :(得分:0)

driver.close();执行driver.switchTo().window(currentWindowHandle);

之后

它会做这项工作。

相关问题