import undetected_chromedriver as uc
options = uc.ChromeOptions()
options.add_argument('--disable-popup-blocking')
...
if step == "0" and not stop_execution:
while True:
try:
driver = uc.Chrome(options=options)
driver.set_page_load_timeout(20)
new_title = f"ABC"
driver.execute_script(f"document.title = '{new_title}';")
# Ensure we kill the old webdriver
kill_old_webdriver()
save_pid(driver.service.process.pid)
except:
# close the browser and try again
driver.quit()
continue
elif step == "1" and not stop_execution:
while True:
try:
driver.switch_to.window(driver.window_handles[0])
# Open a new tab and switch focus to it
driver.execute_script('window.open();')
driver.switch_to.window(driver.window_handles[-1])
time.sleep(1)
driver.get("https://google.com")
time.sleep(1)
With normal Selenium, if step 0 was executed (again), it will open a new Chrome window and killed the previous. But with Undetected ChromeDriver it wont do the same. It wont open anything at all.