Search code examples
pythonseleniumwebdriver

driver.get(url) not executing


I am trying to automate some web scrapping in chrome

Previously I was trying it with a different method where the chrome used to open in guest mode and it was working, here is the previous method

url = 'https://stackoverflow.com/'#Example chrome = webdriver.Chrome(ChromeDriverManager().install())

chrome.get(url)

But when I shifted the method, where the chrome would open logged in by default, it is showing problems, there is no error, but driver.get(url) is not working, infact any lines after webdriver.Chrome... are not working Here is the code after changes

from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options


options = webdriver.ChromeOptions() 
options.add_argument(r"user-data-dir=C:\\Users\user\AppData\Local\Google\Chrome\User Data\Default")

url = "https://www.geeksforgeeks.org/"
driver = webdriver.Chrome(executable_path=r"C:\\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe", options=options)
print("h")

driver.get(url)




Solution

  • This is where you made a mistake.

    driver = webdriver.Chrome(executable_path=r"C:\\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe", options=options)
    

    you need to pass the PATH of the chrome driver Not the chrome browser installed path.

    if you not sure path and your chrome browser compatibility then use below code.

    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)