(Selenium) Cannot display the website when running the code

Hi, I am following Mosh’s Python lesson 11.8 which is about Selenium & automation testing, but I cannot display the website after running the code as follow and no error shown in the VS code. Can anyone help me?

I was having a similar issue when I went through this section.

Can you provide the code you have written so I can take a look at it and see what is going on?

Alright, pulled up my notes from when I was doing this section. From what I remember I ran into some issues that the course versions and today’s versions did not reconcile. As a result some errors were being thrown that after some research were unnecessary. As a result I suppress those arguments & force the window to start maximized (if it isn’t maximized I don’t believe the page appears the same way and it can break your script).

You may also want to check the pathing for your chromedriver exe to ensure it is referenced correctly.

Below is what my code was as of the last time I messed with that section. I hope it helps. If you have further questions this doesn’t help with I can dive back into that section to see if I can sort it out for you.

from selenium import webdriver

from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()


//# to suppress the error messages/logs

options.add_experimental_option(“excludeSwitches”, [“enable-logging”])

driver = webdriver.Chrome(

options=options, executable_path=r"C:\WebDrivers\chromedriver.exe"



signin_link = driver.find_element(“link text”, “Sign in”)


username_box = driver.find_element(“id”, “login_field”)


password_box = driver.find_element(“id”, “password”)



assert “ninjacoder22” in browser.page_source

//# returns the html content of the webpage (assert checks against that info)

Specifically, at a second glance, I believe you are referencing as “browser” and that is no longer what they call it. It is now referenced as “driver” instead. Give that change a try first and go from there.

Thanks for your reply and I have finally get into the github.com now. But I still have two question about this:

  1. Seems your scripts about the chromedriver (line 1-13) is slightly different with Mosh’s, can you teach me in details about the meaning and how to use them?(especially options.add_argument in line 6 and add_experimental_option in line 10)

2.I can get into it by using your script but it still cannot input the username & password automatically cause showing “Unable to locate” errors. Can you help me?

Here are my script and my personal username & password has been hidden(cause I use MacBook Pro I have edited some of the wording inside, hope it will not mess it up!)

Thanks a lot!!

When I was going through this section a couple of weeks ago I hit a roadblock and everything the course was having me try was just not working. This has happened several times over the journey through the python mastery course for me. I decided to give it a rather exhaustive search to figure out what was going on and how to get it to work now.

When I dug into some of the stuff on StackOverflow it turns out that between 2020 when Mosh recorded these videos and now, the team working on chrome driver changed a few variable names and other things as they continued to develop it. In those discussions in the GitHub repo & StackOverflow, I saw that “browser” is now “driver” & along with those changes some new odd errors were being thrown.

After researching those errors I found them to be essentially meaningless for what I was trying to do, and could safely be ignored. That is where the line

options.add_experimental_option(“excludeSwitches”, [“enable-logging”])

comes from. It is intended to stop the errors I was seeing from appearing in the terminal when I was working on the issues that mattered. This line specifically was suggested on I believe the GitHub repository for the project by one of the team members working on it. Further, from my own experiences, it was opening a smaller than normal version of the Chrome window, so the line


was added in order to force the window to be full screen. This made the Github page appear as it does normally & as such all buttons and icons worked appropriately.

As for your second issue: I did not save when I finally had it all working, unfortunately - I moved on to the next problem. The issue you are facing lies in changes to the GitHub coding - if you inspect the page as he instructs in the videos to find the elements and make the changes to those variable names in your current code, it should all start to work for you.

Give that a shot and if you are still having trouble I can give it a bit more of a look. Great work so far!

Hi thanks for your reply. About the second issue, I have done a lot of research and checked the code behind Github.com but still can’t find the reason and then solve the issue, it still cannot locate the element and show the error msg as the screenshot in the previous comment…it makes me frustrated. Can you help me? :face_with_thermometer: :pensive:

When you look through the elements (right click, inspect), you see these below pointing to the Username & password fields

<input type="text" name="login" id="login_field" class="form-control input-block js-login-field" autocapitalize="off" autocorrect="off" autocomplete="username" autofocus="autofocus">

<input type="password" name="password" id="password" class="form-control form-control input-block js-password-field" autocomplete="current-password">

From what I am seeing on StackOverflow your answer probably lies in the find_element itself. I see it as find_element_by_id() on the page, could that be your issue?

I have tried the approach on StackOverflow before and it’s not work now that todays selenium latest version seems no longer support this approach to call the locators.

The selenium latest version is now supporting find_element(By.ID, (value)),and so I have edited the scripts as follow:

Latest version of chromedriver has been installed but still cannot locate the element and solve the issue… I wanna cry!

:sneezing_face: :sneezing_face: :cry: :cry:

You may be missing a small bit of the new format. Try this:

username_box = driver.find_element(By.ID("login_field"));

This page may be helpful, though I am not positive it is relevant for the latest version.

Your other option is to operate this as a virtual environment, essentially pretending it is 2020 to follow along with the course. If you really want to dig into the latest version of chrome driver you can - but in a virtual environment, any changes or adjustments you make won’t break everything else. That way you can run an older version of chrome driver or anything else for that matter and have it only affect this project.

Essentially you can backdate everything to operate as if it was 2020 when Mosh was recording this, and as such, you should run into only the same errors and issues he does in the course.

I found it to be incredibly helpful to operate each project in the course as its own environment, and toward the later stages even utilized GitHub for version control which was a treat. I am sorry you are having so much trouble with this section, but don’t give up!

Thanks for your help very much but unfortunately the new format you mentioned will produce the error that Selenium cannot read “By.ID”, and now the problem still have no idea how to solve… :sob: :sob:

I wondered that is the problem relate to the code in the Sign in to GitHub · GitHub has been changed or not? cause I can locate the element of enter into the login page from Github.com(line 17 on the screenshot in previous comment), which means may relate to the change of the code structure in login page rather then the version of chromedriver/virtual envir,my coding or so on.

I still cannot find where the problem is, can anyone help me? :sneezing_face: :sneezing_face: :pray: :pray: