【问题标题】:Selenium Webdriver - Chrome - Switch Window and back - Unable to receive message from rendererSelenium Webdriver - Chrome - 切换窗口并返回 - 无法从渲染器接收消息
【发布时间】:2014-03-13 14:59:39
【问题描述】:

这是我关于 Stack Overflow 的第一个问题。感谢所有保持技术热情的 StackOverflow 用户。

我正在使用 selenium Webdriver 测试一个 Web 应用程序。这是付款网页,在选择付款方式为“PayPal”后,它会打开一个新的弹出窗口、一个 PayPal 弹出窗口,然后我将窗口切换到 Paypal,进行所有必要的交易。一旦交易成功,paypal 弹出窗口就会自动关闭,我无法从我发起交易的地方返回到原来的窗口。

我在 Eclipse 控制台中收到以下错误:

Starting ChromeDriver (v2.9.248315) on port 25947
[70.164][SEVERE]: Unable to receive message from renderer

以下细节可能会有所帮助:

  • 硒 Webdriver (2.28.0)
  • java - JRE7
  • Google Chrome 版本 - 版本 33.0.1750.146
  • 测试框架 - 测试 NG

这是我的代码:

              // To Switch to Popup/Paypal window

              String currentWindowHandle=driver.getWindowHandle();        

             Set<String> openWindowsList=driver.getWindowHandles();        
             String popUpWindowHandle=null;
             for(String windowHandle:openWindowsList)
             {
             if (!windowHandle.equals(currentWindowHandle))
             popUpWindowHandle=windowHandle;
             }

            driver.switchTo().window(popUpWindowHandle);      
    // Carraying out my paypal transaction        
            driver.manage().window().maximize();
            driver.findElement(By.xpath("//*[@id='loadLogin']")).click();

        Thread.sleep(8000);

        WebElement login_email = driver.findElement(By.xpath("//*[@id='login_email']"));
        login_email.clear();
        login_email.sendKeys(Keys.BACK_SPACE);
        login_email.sendKeys("abc@abc.com");

        WebElement login_password = driver.findElement(By.xpath("//*[@id='login_password']"));
        login_password.clear();
        login_password.sendKeys("abcxyz");
      // Next Click is Final Click on PayPal                        
        driver.findElement(By.xpath("//*[@id='submitLogin']")).click();
      // Transaction is finished on PayPal side and it automatically popup is closed
      //Now i am trying to switch to my last working(original) window
        driver.switchTo().window("My Web Page Title");

【问题讨论】:

    标签: java selenium selenium-webdriver


    【解决方案1】:

    由于页面加载时间过长,您需要在 chromedriver 选项中添加额外的行。

    System.setProperty("webdriver.chrome.driver","E:\\selenium\\chromedriver_2.41\\chromedriver.exe");
    //mention the below chrome option to solve timeout exception issue
    ChromeOptions options = new ChromeOptions();
    options.setPageLoadStrategy(PageLoadStrategy.NONE);
    // Instantiate the chrome driver
    driver = new ChromeDriver(options);
    

    【讨论】:

      【解决方案2】:

      问题已解决。

      我声明 currentWindowHandle 的地方是在点击之后,它将新窗口作为当前窗口句柄。

      我只是将下面的语句移到新窗口点击事件之前。

      String currentWindowHandle=driver.getWindowHandle();
      

      感谢大家的时间和帮助。

      【讨论】:

        【解决方案3】:

        你应该使用:

        driver.switchTo().window(currentWindowHandle);
        

        【讨论】:

        • 感谢您的回复。但是问题仍然存在。 CurrentWindowHandle 没有工作。我仍然无法切换到我原来的窗口。还有什么建议吗?我很乐意尝试
        猜你喜欢
        • 1970-01-01
        • 2018-02-14
        • 1970-01-01
        • 2012-12-31
        • 1970-01-01
        • 1970-01-01
        • 2021-06-17
        • 2019-01-31
        • 2018-07-05
        相关资源
        最近更新 更多