【问题标题】:Tes case Getting failed after closing the Pop Up windowTes case在关闭弹出窗口后失败
【发布时间】:2016-11-25 08:11:25
【问题描述】:

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

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

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

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)

请回复我很长时间以来都陷入了这个问题

【问题讨论】:

  • 请正确格式化您的帖子,可能已经存在一些复制粘贴错误。

标签: selenium selenium-webdriver popup window


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    它会做的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多