You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected await driver.close() to close only the current tab, but it closes the entire browser window instead.
Steps to Reproduce
Open multiple tabs using execute_script("window.open(...);").
Switch to the new tab.
Call await driver.close().
Instead of closing only the new tab, the entire browser session terminates.
Expected Behavior
await driver.close() should close only the currently active tab.
The browser window should remain open with other tabs intact.
Actual Behavior
The entire browser window closes instead of just the active tab.
`
for idx, h2 in enumerate(job_titles, start=1):
try:
# Find inside
# Open new tab for the job link
await driver.execute_script(f"window.open('{job_link}', '_blank');")
await asyncio.sleep(1) # Short delay for tab update
# Get the current tab handles
all_tabs = await driver.window_handles
# Ensure there's more than one tab
if len(all_tabs) <= 1:
logging.warning("No new tab detected, skipping...")
continue
# Identify the new tab (the last handle in the list)
new_tab = all_tabs[-1]
# Switch to new tab
await driver.switch_to.window(new_tab)
# Wait for page to load
try:
await driver.find_element(By.TAG_NAME, 'body')
logging.info("Page loaded successfully")
except Exception as e:
logging.error(f"Error waiting for page load: {e}")
await asyncio.sleep(3) # Let content load
# Print page source before closing tab
page_source = await driver.page_source
logging.info(f"Page Source for job {idx}:\n{page_source[:100]}") # First 100 chars
# Close the new tab only if there are multiple tabs open
remaining_tabs = await driver.window_handles
if len(remaining_tabs) > 1:
await driver.close() # Close the current tab
logging.info("New tab closed successfully")
# Switch back to main tab
remaining_tabs = await driver.window_handles
if main_tab in remaining_tabs:
await driver.switch_to.window(main_tab)
else:
logging.error("Main tab closed unexpectedly!")
else:
logging.warning("Skipping tab close: Only one tab left!")
except Exception as e:
logging.error(f"Error processing job {idx}: {e}")
`
The text was updated successfully, but these errors were encountered:
I expected await driver.close() to close only the current tab, but it closes the entire browser window instead.
Steps to Reproduce
Open multiple tabs using execute_script("window.open(...);").
Switch to the new tab.
Call await driver.close().
Instead of closing only the new tab, the entire browser session terminates.
Expected Behavior
await driver.close() should close only the currently active tab.
The browser window should remain open with other tabs intact.
Actual Behavior
The entire browser window closes instead of just the active tab.
`
for idx, h2 in enumerate(job_titles, start=1):
try:
# Find inside
link = await h2.find_element(By.CSS_SELECTOR, "a")
job_link = await link.get_attribute("href")
logging.info(f"Opening job {idx}: {job_link}")
`
The text was updated successfully, but these errors were encountered: