I m using the https://www.myntra.com/ website for Automating using selenium with java. Once i click on login it shows me option login using Facebook and Google after i click on Sign in with google. how do i take control of the Google sign page using selenium(how to switch control to google sign in window from https://www.myntra.com window using selenium) they are in the same browser
Asked
Active
Viewed 180 times
0
-
I have added an answer for that. Please let me know your results – Mahmud Riad Dec 28 '17 at 12:46
-
For reference you can also check this https://stackoverflow.com/questions/47572527/how-to-control-the-newly-opened-window-that-appears-after-a-click-in-selenium-we/47572795#47572795 – Mahmud Riad Dec 28 '17 at 12:47
3 Answers
0
To switch the control to new window using selenium the implementation is below
String mainWindowHandler = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
Please let me know your feedback
Mahmud Riad
- 1,169
- 1
- 8
- 19
0
String parentHandle = browser.getWindowHandle();
browser.findElement( By.cssSelector(".desktop-userIconsContainer") ).click();
browser.findElement( By.linkText("LOGIN") ).click();
browser.findElement( By.id("gPlusLogin") ).click();
for (String googleHandle : browser.getWindowHandles() ){
browser.switchTo().window(googleHandle);
}
new WebDriverWait(browser, 10)
.until(ExpectedConditions.elementToBeClickable( By.id( "identifierId" ) )).sendKeys("yoyo");
browser.switchTo().window(parentHandle); // use this for switching back to parent window
roshi
- 68
- 1
- 1
- 5
-
1Please edit your answer to include an explanation as to how and why your code solves the problem. – Eric Hauenstein Dec 28 '17 at 16:50
0
Once you click() on the link GOOGLE a new Window is opened. So you have to change the Window through WindowHandles as follows :
String first_win = driver.getWindowHandle();
driver.findElement(By.xpath("your_xpath")).click();
new WebDriverWait(driver,5).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> s1 = driver.getWindowHandles();
Iterator<String> i1 = s1.iterator();
while(i1.hasNext())
{
String next_win = i1.next();
if (!first_win.equalsIgnoreCase(next_win))
{
driver.switchTo().window(next_win);
System.out.println("Working on Sign In Window");
}
}
undetected Selenium
- 183,867
- 41
- 278
- 352