'NameError: name 'webdriver' is not defined error using Selenium and Python

Am receiving this error that WebDriver is not defined and not sure what is causing it.

Code:

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import datetime as dt
import pandas as pd

# Opening the connection and grabbing the page
my_url = 'https://www.google.com/webhp?hl=en'
option = Options()
option.headless = False
driver = webdriver.Chrome(options=option)
driver.get(my_url)
driver.maximize_window()

And the error message:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-36e4c75bf698> in <module>
     10 option = Options()
     11 option.headless = False
---> 12 driver = webdriver.Chrome(options=option)
     13 driver.get(my_url)
     14 driver.maximize_window()

NameError: name 'webdriver' is not defined

Am running it on Jupyter notebooks.

Any ideas folks?



Solution 1:[1]

This error message...

NameError: name 'webdriver' is not defined

...implies that NameError was raised while executing the line:

driver = webdriver.Chrome(options=option)

as you haven't imported the webdriver module.:


Solution

Apart from importing the other modules you also have to include the webdriver module as follows:

from selenium import webdriver

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium