尝试自动化电子商务网站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();
非常感谢您解决此问题的任何帮助。
答案 0 :(得分:0)
使用SET首先存储父窗口和子窗口,然后迭代它。我没有尝试过你的代码,但是这种使用SET和迭代器的逻辑必须适合你。