0

Here is my code:

from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()
driver.get("http://www.google.com")

sleep(3)
driver.quit()

Chrome version is 104.0.5112.102 ChromeDriver version is 104.0.5112.20 Selenium version is 4.10.0

I tried to restart my PyCharm and close all Chrome and restart my PC

greybeard
  • 2,249
  • 8
  • 30
  • 66

3 Answers3

0

an error log might be helpful but i think you should specify the path to the chromedriver.exe

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep


chromedriver_path = './chromedriver.exe'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options, executable_path=chromedriver_path)
driver.get("http://www.google.com")
sleep(3) driver.quit()

'./chromedriver.exe' means chromedriver is in the project root folder and you can add options to chromedriver such as

options.add_argument("--disable-blink-features")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

to avoid getting detected as a bot so it would be like this

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep


chromedriver_path = './chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=chromedriver_path)
driver.get("http://www.google.com")
sleep(3) driver.quit()
CatChMeIfUCan
  • 569
  • 1
  • 7
  • 26
  • Thank you for your reply~ This question has been bothering me all day Then I realized that the uninstalled high version of Chrome did not remove it for some reason, and the error message was about the path of the high version of Chrome, but I didn't notice it, and I thought the error message was about the path of the low version of Chrome. There is a high version of Chrome and a low version of Chrome (same path setting as Chrome in Pycharm). Manually deleted them and it worked! Thanks again! – ran jin Jul 27 '23 at 08:38
0

According to the code you shared, it looks like you're missing the path of chromedriver

from selenium import webdriver
from time import sleep

# Add the path to your chromedriver
driver = webdriver.Chrome('C:\\chromedriver_win32')
driver.get("http://www.google.com")

sleep(3)
driver.quit()
I.sh.
  • 252
  • 3
  • 13
  • Thank you for your reply~ This question has been bothering me all day Then I realized that the uninstalled high version of Chrome did not remove it for some reason, and the error message was about the path of the high version of Chrome, but I didn't notice it, and I thought the error message was about the path of the low version of Chrome. There is a high version of Chrome and a low version of Chrome (same path setting as Chrome in Pycharm). Manually deleted them and it worked! Thanks again! – ran jin Jul 27 '23 at 08:39
  • I'm pretty sure you meant chromedriver not Chrome. happy to help! – I.sh. Jul 27 '23 at 13:32
0

Are you trying this? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

code:

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')```
Morphey
  • 1
  • 1
  • Thank you for your reply~ This question has been bothering me all day Then I realized that the uninstalled high version of Chrome did not remove it for some reason, and the error message was about the path of the high version of Chrome, but I didn't notice it, and I thought the error message was about the path of the low version of Chrome. There is a high version of Chrome and a low version of Chrome (same path setting as Chrome in Pycharm). Manually deleted them and it worked! Thanks again! – ran jin Jul 27 '23 at 08:39