0

I am trying to click "OK" on my localhost for a popup window that is generated with Jquery. I tried switching to the window that didn't work

handleName = driver.window_handles
driver.switch_to.window(handleName)

then I also tried doing a javascript popup but its a Jquery so it wouldn't work

alert = browser.switch_to_alert()
alert.accept()
browser.close()

what are my other options?

1 Answer 1

1

driver.window_handles returns a list of all opened windows. Just tried switch_to.window() and it raised error because it needs only one name and not a list.

  1. If jquery generates actual browser window you can switch to the popup window by its name/title if it has one:

    driver.switch_to.window("Alert popup!")

In the situation when the current and popup windows have equal titles I use something like this:

current_window = driver.current_window_handle
_handles = driver.window_handles
<popup opening button>.click()
WebDriverWait(driver, timeout).until(
    expected_conditions.new_window_is_opened(_handles))
try:
    #find new window handle
    popup_window = (h for h in
            driver.window_handles if h != current_window).next()
except StopIteration:
    raise Exception("No popup!")
  1. If jquery generates some popup-styled <div> (not browser window), so you just locate it like any other element on the page with driver.find_element_by_<...>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.