Selenium : window does not open after click

Viewed 205

I am using selenium 3.4.3 and python 3.6.2 and I have a problem when I want to open a new window. First of all here is the part of the code where it fails :

def wait_and_find_by_id(element_id):
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, element_id))
    )
    return driver.find_element_by_id(element_id)

VA = wait_and_find_by_id('VA_id')
driver.execute_script("window.showModalDialog = window.open;")
VA.click()

# Wait for the new window to open
time.sleep(2)
driver.switch_to_window(driver.window_handles[2])

tarifaire = driver.find_element_by_xpath("//*[@id='tarif_id']/span/span")
driver.execute_script("window.showModalDialog = window.open;")
tarifaire.click()

I have no problem with the first window opening (VA.click()) but when I try to open the second window (tarifaire.click()), the window seems to refresh and nothing else happens.

I tried to run the script without the second instance of driver.execute_script, and the window opens but as a popup, and my program is stuck as long as I don't close the popup.

I can give you more information if you need it to help me.

Update : Turns out it works well with ChromeDriver, I don't even have to use driver.execute_script. But still, if someone knows why the above script does not works with Firefox's Geckodriver, I'd be glad to hear it !

0 Answers
Related