Webdriver.chrome not opening chrome

1.3k views Asked by At

I'm working on an automation script and I'm trying to open a url in chrome, I have installed and imported selenium and downloaded the chrome driver and moved it to /usr/local/bin.

But when I try and run the script, the console is blank and then about a second later it displays 'Process finished with exit code 0' as if nothing happened. Below is my current code:

from selenium import webdriver


class Script():
    def __init__(self):
        self.driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver')

    def login(self):
        self.driver.get('https://facebook.com')
3

There are 3 answers

3
Gokul nath On

The path is wrong here. It should be like below webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver.exe') Need to add .exe extension in the executable_path. Also, make sure you are using correct Version of chrome driver for Google Chrome.

3
Larry Atherton On

Does this work?

from config import keys
from selenium import webdriver

def order():

    driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
    driver.get('https://facebook.com')
    print("here")

if __name__== '__main__':
    order()

An exit code 0 means that ran without error. If an error occurs it would provide a non-zero argument. I would add a

from selenium import webdriver


class Script():
    def __init__(self):
        self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

    def login(self):
        self.driver.get('https://facebook.com')
        print ('Opened facebook')

This should return with "Opened facebook" then 'Process finished with exit code 0'. I built something similar that will log a user into Facebook.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

class Script():
    def __init__(self):
        self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

    def login(self):
        self.driver.get('https://facebook.com')
        print ('Opened facebook')       
        self.driver.implicitly_wait(30)
        self.driver.get(k['product_url'])
        print ('Opened facebook')
        username_box = self.driver.find_element_by_id('email')
        username_box.send_keys('EMAIL ADDRESS')
        print ('Email Id entered')
        password_box = self.driver.find_element_by_id('pass')
        password_box.send_keys('password')
        print ('Password entered')
        login_box = self.driver.find_element_by_id('loginbutton')
        login_box.click()
        print('Logged In')
0
undetected Selenium On

You are on system. You don't need the raw i.e. r switch. Your effective line of code will be:

self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')