4

This is my code script:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\hadi\\AppData\\Local\\Google\\Chrome\\User Data") #Path to your chrome profile
w = webdriver.Chrome(executable_path="E:\Python\chromedriver.exe", chrome_options=options)
w.get("https://www.facebook.com")

and on running this script i'm getting this error:

Traceback (most recent call last):
  File "E:/Python/MoosaBhai/TestoTes.py", line 6, in <module>
    w = webdriver.Chrome(executable_path="E:\\Python\\chromedriver.exe", chrome_options=options)
  File "C:\Users\hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Users\hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\hadi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)

I've edited my executeable path to chromedriver but when i run the script my chrome driver opens but after that stuck for 2-3minutes and then crashes with the above following error.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
GigaByte
  • 700
  • 6
  • 21

1 Answers1

0

Thumb rule

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


As per your code trials seems you are trying to access a Chrome Profile so you can use the following solution:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.add_argument("user-data-dir=C:\\path\\to\\your\\profile\\Google\\Chrome\\User Data\\Profile 2")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
    driver.get("https://www.google.co.in")
    
  • Here you can find a detailed discussion in How to open a Chrome Profile through Python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    sir,Cant i use my default profile in chrome webdriver? – GigaByte Aug 31 '18 at 09:35
  • 1
    @GigaByte Your _default chrome profile_ would include a lot of _bookmarks_, _extensions_, _theme_, _cookies_ etc. _Selenium_ may fail to load it. So as per the best practices create a new _chrome profile_ for your `@Test` and store/save/configure within the _profile_ the required data. – undetected Selenium Aug 31 '18 at 09:39
  • mean when i create the @test profile for me, then can i be able to use the cache of that active profile afterward? mean the searches that i will make? – GigaByte Aug 31 '18 at 09:45
  • @GigaByte Broadly the answer is **Yes**. As of now, my tests stores _cookies_ extensively. It would depends on your _Test Criteria_ what you need to store. Of-coarse you should avoid storing _unwanted data_ to keep the _profile_ light so _Selenium_ can be able to load it runtime. – undetected Selenium Aug 31 '18 at 09:49
  • i just want to store the cookies and cache for 3 URLs so profile will be light. – GigaByte Aug 31 '18 at 09:50
  • 1
    https://stackoverflow.com/questions/49270109/how-to-open-a-chrome-profile-through-python/49280195#49280195 will this link be helpful for creating and using webdriver profile? – GigaByte Aug 31 '18 at 09:51
  • Go ahead, But I guess when you say `3 URLs` it means `3 different URLs` so you have to store the cookies of `3 URLs` logically **separate** so they don't get mixed up. – undetected Selenium Aug 31 '18 at 09:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/179169/discussion-between-gigabyte-and-debanjanb). – GigaByte Aug 31 '18 at 09:55
  • sir, i'm not getting my profile loaded as shown in the snapshot of your link provided above { https://stackoverflow.com/questions/49270109/how-to-open-a-chrome-profile-through-python/49280195#49280195} using my path: path = "C:\Users\hadi\AppData\Local\Google\Chrome\User Data\Profile 3" – GigaByte Aug 31 '18 at 10:38
  • @GigaByte What have you saved in your _crome profile_? What does the error says? – undetected Selenium Aug 31 '18 at 11:02
  • i got no error. I saved password in my chrome profile and use only 1 link to test. I gave the absolute path to my profile which is: C:\Users\hadi\AppData\Local\Google\Chrome\User Data\Profile 3 But when chromewebdriver opens it start with its own profile rather than the one which i have created newly. – GigaByte Aug 31 '18 at 11:04
  • 1
    getting the results. You save my day sir. I was trying that from recent 2 days and now got the result because of you. Always you're there on my post to help, thanks alotttttttt. – GigaByte Aug 31 '18 at 11:11