Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Quality Assurance Introduction to Selenium Test Drive Selenium Installation

Nikita Novikov
Nikita Novikov
5,929 Points

Uncaught ReferenceError: driver is not defined

After typing "driver.get(url);" I got "Uncaught ReferenceError: driver is not defined" error message. How do i solve this problem?

Steven Parker
Steven Parker
231,236 Points

You need to provide more information. Take a look at this video about Posting a Question), and perhaps also this one about sharing a snapshot of your workspace.

Caleb Kemp
Caleb Kemp
12,755 Points

I am glad Steven Parker mentioned that, without sufficient information, it isn't always possible to find a solution. I don't know for certain, but from what you posted, I think you might have an iframe reference (scope) problem. Let me see if I can show you what I mean by that. In the following code, we see that even though we have let max = 5 higher up in the code, running console.log(max) will cause an error because they are not of the same scope. The variable max has not been defined outside the "if" block.

if(1 == 1){
  let max = 5;
}
console.log(max)

In the case of iframe's, you can have something similar, something like the following

iframe(parent){
  iframe(child){
    const driver = new selenium.build;
  }
  //I think you can see how running "driver.get" here will cause a reference error because it is out of scope
  driver.get(url);
}

To fix this, we have to make sure that your "driver.get(url)" call is in the correct scope. Adding something like the following before your "driver.get(url)" call may do the trick.

//here within iframe (child)
driver.switchTo().frame("parent");
driver.switch_to_default_content();

Here is a link to a post a person's explanation of this. I don't know 100% this is your problem, however, it does seem reasonably likely from the information posted. Hope that helps!