1

I use selenium 2 and the browser version is IE 11. I face issue while handling with pop up.

Scenario 1:

driver.findElement(By.id("I create modal window")).click();
Set<String> windows = driver.getWindowHandles();
System.out.println(windows.size());

I get the output as 2.

Scenario: 2 (with the same concept)

driver.findElement(By.id("I create pop up")).click();
Set<String> windows = driver.getWindowHandles();
System.out.println(windows.size());

I get the output as 1.

I could not switch to the pop-up. Some times the pop-up response like not connected and moreover the size of the popup is way smaller than what it should be.

What would be the problem

Note : The element id's are not real one

4 Answers4

0

From your question it looks like you wanted to switch to a pop - up.

Window handler is used to switch between browser windows.

Alert handler is used to switch between the pop - up messages.

If you wanted to accept/yes/ok the alert:

Alert alert = driver.switchTo().alert();
alert.accept();

If you wanted to dismiss/no/cancel the alert:

Alert alert = driver.switchTo().alert();
alert.dismiss();
Ashok kumar Ganesan
  • 1,098
  • 5
  • 20
  • 48
0

You have to first check its window or alert.

Simply try to inspect element in that popup, if you are able to inspect elements in popup then its window so use switch to window command, if not then it is alert. So use switch to alert command (which provided in another answer)

murali selenium
  • 3,847
  • 2
  • 11
  • 20
  • try it. https://stackoverflow.com/questions/46966305/selenium-with-ie11-does-not-identify-the-other-window-opens-using-windows-handle – murali selenium Jul 23 '18 at 10:43
  • already checked and try, and it does not work. I look what have already been done befor asking ^^ but thanks anyway – clement guellec Jul 23 '18 at 12:32
  • @clementguellec accepted question. As of what i know 1. doing settings as specified https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver 2. using 32bit if using 64 bit once 3. thread.sleep after click which leads to new windows. i hope you already done those. Even for my project IE not working, my question is up voted but no solution. – murali selenium Jul 23 '18 at 17:09
0

There are different types of alerts and it should be handled differently as given below.

  1. Windows type: if your popup opened in a new window, you can handle it using get window handle and switch to window methods.

    driver.selectElement(By.id("I create modal window")).click(); Set<String> windows = driver.getWindowHandles(); System.out.println(windows.size()); for( String window : windows) driver.switchToWindow(window);

  2. Javascript alert: if the popup is javascript type. you can use switch to alert method.

    Alert alert = driver.switchTo().alert();

  3. DOM Element type: sometimes the popup is like DOM Element, created dynamically or hidden until popup. It can be handled using find elemeent method.

    driver.findElement(locator).Click();

Murthi
  • 5,299
  • 1
  • 10
  • 15
  • thanks for answering : 1 i did the same code but i didn't put the for in my question, and it didn't work. 2, it's not an alrt. 3 it might help, buthow am i suppose to get the Locator, with inspect the sources or inspect the element, i have nothing that seems to help me? and i couldn't find an element in the popup from my program – clement guellec Jul 23 '18 at 10:35
  • share you html code or popup screenshot, so that,we can identify the type of popup you have? – Murthi Jul 23 '18 at 10:38
  • i can't give you a screen, i need to be level 10 (???) and my html code is aroud 5K lignes, i send you the interesting part – clement guellec Jul 23 '18 at 12:13
  • i'm a trainee, and i'm not sure i can put the code online, the pop up is a regular window, with no tab. it's not modal. – clement guellec Jul 23 '18 at 12:30
0

I haven't fix my problem, but I found interesting things : when i open a popup, it is not connected to the current session if i open my web site with Selenium, even if don't ask Selenium to open my popup but i do it my self. If id do :

driver.quit()

the Main window will be close but not the popup