切换回父窗口并对父窗口执行操作会引发JavaScript错误

切换回父窗口并对父窗口执行操作会引发JavaScript错误,javascript,selenium,Javascript,Selenium,尝试自动化电子商务网站,SnapDeal 我在控制台中遇到此错误: 从子窗口切换到父窗口并尝试在父窗口上执行某些操作时 //Logging in to SnapDeal using Facebook. SnapDeal.findElement(By.xpath("//div[@id='fbUserLogin']")).click(); String pWindow = SnapDeal.getWindowHandle(); for (String winHan

尝试自动化电子商务网站,SnapDeal

我在控制台中遇到此错误:

从子窗口切换到父窗口并尝试在父窗口上执行某些操作时

    //Logging in to SnapDeal using Facebook.

    SnapDeal.findElement(By.xpath("//div[@id='fbUserLogin']")).click();
    String pWindow = SnapDeal.getWindowHandle();
    for (String winHandle : SnapDeal.getWindowHandles()) 
    {
           //Switch to child window 
           SnapDeal.switchTo().window(winHandle);
    }

    WebElement FBLoginID = SnapDeal.findElement(By.xpath("//input[@id='email']"));
    JavascriptExecutor js = (JavascriptExecutor)SnapDeal;
    js.executeScript("arguments[0].value='YourEmailID';", FBLoginID);

    WebElement FBPass = SnapDeal.findElement(By.xpath("//input[@id='pass']"));
    JavascriptExecutor jE = (JavascriptExecutor)SnapDeal;
    jE.executeScript("arguments[0].value='YourPassword';", FBPass);
    SnapDeal.findElement(By.xpath("//button[@id='loginbutton']")).click();
    SnapDeal.findElement(By.xpath("//button[@name='__CONFIRM__']")).click();
    Thread.sleep(5000);

    //Switching back to parent window
    SnapDeal.switchTo().window(pWindow);

    //logging out of the application in the parent window post switching 
    WebElement WelCome = SnapDeal.findElement(By.xpath("//span[contains(.,'Welcome')]"));
    WebElement LogOut = SnapDeal.findElement(By.xpath("//a[contains(.,'Logout')]"));
    Actions mousehover = new Actions(SnapDeal);
    mousehover.moveToElement(WelCome).perform();
    Thread.sleep(5000);
    mousehover.click(LogOut).perform();

如果您能帮助解决此问题,我们将不胜感激。

请使用SET先存储父窗口和子窗口,然后对其进行迭代。我还没有尝试过您的代码,但使用SET和迭代器的这种逻辑必须适合您。

这可能是在访问不再连接到DOM的对象;哪一行抛出此错误?您得到的错误是什么?@kushal:在切换回父窗口并对其执行某些操作时抛出错误。上面已经提供了代码段。@Shailendra:@Dannie:此行String pWindow=SnapDeal.getWindowHandle()fbLogin按钮之前执行code>。