Search code examples
pythonselenium-webdriverselenium-chromedriver

how can i open the chrome browser using selenium


i need a basic code which opens the chrome browser, but the code isnt working my chrome version is Version 123.0.6312.106 (Official Build) (64-bit) https://chromedriver.chromium.org/downloads There is no chromedriver specific for my version, but there is a test chrome i tried using both. can someone guide me through this , iam a beginner to this selenium

from selenium import webdriver
chromepath = r"C:\Users\hp\Desktop\Automation\chromedriver.exe"
driver = webdriver.Chrome(chromepath)
driver.get('http://www.google.com')`

i tried the above but not working showing error:AttributeError: 'str' object has no attribute 'capabilities'

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

but when i add the path as system variable the chrome is opening for a second and closing

showing error:The chromedriver version (114.0.5735.90) detected in PATH at C:\Users\hp\Desktop\Automation\chromedriver.exe might not be compatible with the detected chrome version (123.0.6312.106); currently, chromedriver 123.0.6312.105 is recommended for chrome 123.*, so it is advised to delete the driver in PATH and retry


Solution

  • Try this:
    In the terminal:

    pip install chromedriver_py
    

    Script:

    from selenium import webdriver
    from chromedriver_py import binary_path
    svc = webdriver.ChromeService(executable_path=binary_path)
    driver = webdriver.Chrome(service=svc)
    driver.get('http://www.google.com')
    input("Press any key to exit.")
    driver.quit()