Sriharsha Karanth
Sriharsha Karanth

Reputation: 47

how to handle multiple popups at the same time

i was asked a question if we can handle multiple popups in selenium web driver. frankly i dont know it.

But is it the right way . Assume that we are doing it and we have 3 popups on our screen. so :

Please correct me if im wrong. Thanks and Good day. - S.K

Upvotes: 1

Views: 3344

Answers (1)

Kache
Kache

Reputation: 16677

As Faiz mentioned in the comments, a reference to each window is stored in the driver.window_handles array.

The first handle should be your main window, so closing popups (in Ruby) might go something like this:

driver.window_handles[1..-1].each do |handle|
  driver.switch_to.window(handle)
  driver.close
end
driver.switch_to.window(driver.window_handles.first)

Handling a few edge cases like alerts and thrown exceptions will take a bit more code though.

Upvotes: 1

Related Questions