Skip to content

When trying to output a window handle after a new window and alert, webdriver hangs and freezes. #14795

@indpyamamoto2403

Description

@indpyamamoto2403

What happened?

1.Open a new window.
2.Outputs an alert.
3.Outputs the window handle.

Normally, this would return an error due to alert being active, but in this case it freezes and further operations become impossible.

Error handling is difficult, so we would appreciate it if you could address this issue.

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.chrome.service import Service
import time
# Initialize the Chrome driver
driver = webdriver.Chrome()

# Open Google in the first window
driver.get("https://www.google.com")

# Open a new window and switch to it
driver.execute_script("window.open('');")

# driver.switch_to.window(driver.window_handles[1])

# Open Google in the new window
driver.get("https://www.google.com")

# Display an alert
alert = Alert(driver)
alert_text = "This is an alert"
driver.execute_script(f"alert('{alert_text}');")
print(1)
# Print the window handles
time.sleep(5)
print(driver.window_handles)
print(2)
# Close the driver after a short delay
time.sleep(5)
driver.quit()

Relevant log output

1

Operating System

Windows

Selenium version

4.22

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions