[英]Switching back to parent window and performing action on parent throws JavaScript error
尝试自动化电子商务网站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和迭代器的这种逻辑必须对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.