All I want is to close a modal dialog, ideally by doing the following:
browser.find_element_by_link_text("OK").click()
Gives NoSuchElementException: Message: u'The element could not be found' for the OK link text.
Same for the xpath when I do this:
browser.find_element_by_xpath("//*[@id=\"modal\"]/div/div[2]/div/a").click()
I suspect this is because I need to put focus on the dialog. To do so I've tried:
for handle in browser.window_handles:
    browser.switch_to_window(handle)
    if browser.find_element_by_class_name('popUp123')
        browser.find_element_by_link_text("OK").click()
Gives NoSuchElementException: Message: u'The element could not be found' for the class.
Have also tried browser.switch_to_frame(ID OR NAME), but couldn't find it as a frame either.
Please tell me I'm missing something blatantly obvious.
Relevant frame source (summarised):
<body id="modal">
    <div class="popUp123">
    <div class="button">
        <div class="centerbutton">
            <a href="#" class="close" onclick=parent.close">
                <span>OK</span>
                This is the python syntax
from selenium.webdriver.remote.webdriver import WebDriver
browser = WebDriver()
# do other stuff here
browser.switch_to_alert().accept()
# continue with other stuff here
The alert api is located in selenium.webdriver.common.alert
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With