0

Is it possible to automatically focus to the pop-up (be it a modal window or a dialog box) after clicking a link.

I found something like this from How can selenium web driver get to know when the new window has opened and then resume its execution

driver.find_element_by_id("id of the button that opens new window").click()        
WebDriverWait(driver, timeout=50).until(found_window("new window name"))
WebDriverWait(driver, timeout=10).until( # wait until the button is available
    lambda x: x.find_element_by_id("id of button present on newly opened window"))\
    .click()

But even here we need to know the id or any attribute of the pop-up. Is there some way we can run an automated script in Selenium so that it catches any pop-up window and auto-focus to that and returns back to the parent window only once the tests are performed on the pop-up.

Thanks in advance!

P.S. I use Selenium-Python

1 Answers1

0
alert = driver.switch_to_alert()

for accept it

alert.accept()

Have a look here:

How to test Alert/Popup in Selenium using Python

Check if any alert exists using selenium with python

Carlo 1585
  • 1,455
  • 1
  • 22
  • 40
  • @Carlo 1585 Thanks for your response.But doesn't this go only for alert boxes? To clarify - By 'pop-up' I meant any window that would pop-up other than alert boxes. That is why I didn't mention alert box but other pop-up dialog box or modal windows. – pythonic_autometeor Sep 29 '17 at 09:23
  • Hi guys, yes it should work only for alert but if you try it in the real life scenario it will work even for pop-up; I used it with python 2.7 and for me worked without problems! I even interact with a window to browse on your desktop and upload an image, after I got other problem with the same page but doing the switch_to_alert I could move to the pop-up. Give it a try ;) – Carlo 1585 Sep 29 '17 at 09:57
  • @Carlo 1585 My requirement is that if such a case is possible, I need to fetch all the links present in the pop-up. But with the following command I didn't find a way. Could you please help me here. – pythonic_autometeor Sep 29 '17 at 10:44
  • I think you can find what you are searching for in this 2 post (I add them to my answer) – Carlo 1585 Sep 29 '17 at 10:58