Selenium: window doesn't open after click
I am using selenium 3.4.3 and python 3.6.2 and I have a problem where I want to open a new window. First of all, this 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 opening a window for the first time ( VA.click()
), but when I try to open a second window ( tarifaire.click()
), the window seems to be refreshed and nothing else happens.
I tried to run the script without a second instance driver.execute_script
and the window opens but as a popup and my program gets stuck until I close the popup.
I can give you more information if you need it to help me.
Update. It turns out this works well with ChromeDriver, I don't even need to use driver.execute_script
. But still, if anyone knows why the above script doesn't work with Firefox Geckodriver, I'd love to hear it!
No one has answered this question yet
See similar questions:
or similar: