0

The simple code like this:


    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get('https://www.baidu.com')

It runs well , but! The opened browser quit automatically. Some infos below

  1. i have more selenium develop experience , this issue i met it these days on teaching my students.
  2. chromedriver version : 107.0.5304.62
  3. chrome version : 107.0.5304.107
  4. selenium version : 4.6
  5. python version : 3.10

It can work fine on an other PC1. I can't find the difference between them. I try to collect the selenium log .


    from selenium import webdriver
    driver = webdriver.Chrome(service_args=['--verbose'],service_log_path='selenium.log')
    driver.get('https://www.baidu.com')

I get the log on PC1 too. I found the difference , but i can't sure it is the source of this issue , also i can't solve it.

Here is the doubtful point: [1669339280.964][INFO]: [9a850cc416a680214e963aab4064f86b] COMMAND QuitAll { } [1669339281.111][INFO]: [9a850cc416a680214e963aab4064f86b] RESPONSE QuitAll That's all , please give me some advices. Thank u.

1 Answers1

0

You have to use Options:

from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(<chromedriver.exe path>), options=options)
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • Thank u . But i dont agree ur idea . The same code runs well on the other PC, it won't quit automatically, how to explain this , i write the same code for a long time . It always works fine, only 2% students' enviroment have this issue. – wuxianfeng023 Nov 25 '22 at 12:55
  • I also search and got ur code on the web, but i didn't agree this. – wuxianfeng023 Nov 25 '22 at 12:56
  • I was also facing this issue You can refer https://sites.google.com/a/chromium.org/chromedriver/capabilities - check 'detach'. If you don't agree that too, sorry, best of luck. – AbiSaran Nov 25 '22 at 13:31
  • Thank u bro. I downgrade my selenium version 4.6-> 4.3 . It works well. – wuxianfeng023 Nov 26 '22 at 12:30