0

EDIT: The code is failing after the first line. I have reinstalled Google Chrome, reinstalled the webdriver, and selenium, however I can't seem to resolve the issue. The screenshot is attached. I'm also Image here! MacOS. Thank you @Dimitri T and @Omer Tekbiyik for your assistance thus far!

I am trying to use selenium and python using chromedriver, but I can't seem to get past a string of errors. I've troubleshooted using just about everything. Any help would be greatly appreciated!


from selenium import webdriver
# os.environ["webdriver.chrome.driver"] = chromedriver
# browser = webdriver.Chrome(chromedriver)
# browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-# ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")

# title = browser.title
# print(title)

Here is the Code I have tried. I've also tried this...

from selenium import webdriver

# browser = webdriver.Chrome()
# browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-# # ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")

# title = browser.title
# print(title)

I expect it to launch a webpage, however, I just get a string of errors.

Traceback (most recent call last):
  File "/Users/trapbookpro/Downloads/PythonLoginScripts/yes.py", line 1, in <module>
    from selenium import webdriver
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 21, in <module>
    import copy
  File "/Users/trapbookpro/Downloads/PythonLoginScripts/copy.py", line 10, in <module>
    lst1()
1
  • Maybe something to do with the python being a different version? I've been having the same Commented Jul 4, 2019 at 3:59

3 Answers 3

1
  1. Let's start clean. Install Selenium package using PIP.

    pip install -U selenium
    
  2. Download and install Chrome
  3. Download Chromedriver (make sure to choose the matching version for your Chrome browser version)
  4. Amend your code to look like:

    from selenium import webdriver
    
    browser = webdriver.Chrome("c:\\path\\to\\chromedriver.exe")
    browser.get(
        "https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")
    title = browser.title
    print(title)
    browser.quit()
    
  5. That's it, your script should be working now:

    enter image description here

More information including installation, configuration steps and a sample project: Selenium With Python

Sign up to request clarification or add additional context in comments.

1 Comment

I uninstalled selenium, uninstalled chrome, and reinstalled the chromedriver. The chrome driver ends in .90 and my chrome version ends in .100, but everything else is the same. @Dimitri T, I don't think it's working past my first line: from selenium import webdriver. It's immediately throwing the error and I don't know why. I'm not even able to get to the code! This is so frustrating.
0

You just need to add driver path like:

driver_path = r'your driver path'
browser = webdriver.Chrome(executable_path=driver_path)

and get titles like :

from selenium import webdriver

driver_path = r'your path'
browser = webdriver.Chrome(executable_path=driver_path)
browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")
title = browser.title
print(title)

Output :

NYU Login

2 Comments

Even when I do that, from selenium import webdriver driver_path = r'/Users/trapbookpro/Downloads/PythonLoginScripts/Drivers/chromedriver' browser = webdriver.Chrome(executable_path=driver_path) I still get the same error. That's the exact path of it. Am I doing something wrong still?
Upon further examination, even if I type the first line from Selenium import webdriver, I get the same errors.
0

I found a solution to this problem! After experimenting with Jupyter I found a way to make this script work!

sudo -H pip3 install -U selenium
sudo -H pip3 install urllib3
sudo easy_install selenium 

This works perfectly and also running my script in python3 allowed me to successfully run this script. Thank you, everyone, for everything!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.