1

I created a virtualenv with the required packages. Activated the env. Now I keep getting the following: ImportError: cannot import name webdriver. I've checked my env and all of my files seem to be right. Can anyone offer input? I'm including a code drop link and screenshot.

https://drive.google.com/open?id=1jzVoBilX9pU3CYC2czQ3IBRE87sCWJ3k

import time
from selenium import webdriver    # this is the offending line
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException


def init_driver():
    driver = webdriver.Firefox()
    driver.wait = WebDriverWait(driver, 5)
    return driver


def lookup(driver, query):
    driver.get("http://www.google.com")
    try:
        box = driver.wait.until(EC.presence_of_element_located(
            (By.NAME, "q")))
        button = driver.wait.until(EC.element_to_be_clickable(
            (By.NAME, "btnK")))
        box.send_keys(query)
        button.click()
    except TimeoutException:
        print("Box or Button not found in google.com")


if __name__ == "__main__":
    driver = init_driver()
    lookup(driver, "Selenium")
    time.sleep(5)
    driver.quit()

Image of error

gary
  • 4,227
  • 3
  • 31
  • 58
  • Just added the code... – Josh Frazier Feb 16 '18 at 14:48
  • 2
    change your current file name to something other than `selenium.py`. Python is looking for webdriver in your own code which it can't find to import, instead of going to the actual `selenium.py` to look for.. – MooingRawr Feb 16 '18 at 14:50
  • I renamed it to magnolia.py and initialized the code. I still got this error. Traceback (most recent call last): File "/Users/josh.frazier/Desktop/python_play/env/magnolia.py", line 2, in from selenium import webdriver ImportError: cannot import name webdriver [Finished in 0.042s] – Josh Frazier Feb 16 '18 at 14:55
  • are there any other files named `selenium.py`? – MooingRawr Feb 16 '18 at 14:58
  • Tehre is a selenium.pyc file in the env – Josh Frazier Feb 16 '18 at 15:05
  • delete that as well. – MooingRawr Feb 16 '18 at 15:08
  • Unfortunately, that didn't work either. – Josh Frazier Feb 16 '18 at 15:56
  • Welp out of ideas, either you didn't install selenium correctly (which I doubt since you would get a different error message, or that there's a selenium.py(c) floating around that interfering with it. – MooingRawr Feb 16 '18 at 16:18
  • Well I appreciate the attemp MooingRawr! – Josh Frazier Feb 16 '18 at 19:25
  • I would try the suggestions in this [thread](https://stackoverflow.com/q/29092970/404469) including this [answer](https://stackoverflow.com/a/50641487/404469) which involves uninstalling selenium and reinstalling an older version to support the version of Python you are using. – gary Jan 03 '19 at 16:42

0 Answers0