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 Automation Nation Getting Started

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Selenium and the Visual Studio Code Integrated Terminal

I've made a bit of a breakthrough with Selenium tonight.

For almost as long as I've been following the Selenium Course here on Treehouse, I've been struggling with Selenium... not with following on but with bugs that keep crashing the automated Chrome instances.

It struck me that every time I was supposed to follow along using the VS Code integrated terminal, I didn't. One reason for that is because I couldn't set up Git Bash on the terminal, for whatever reason. Tonight, I did. And.... Presto.

When I ran the code below...

const selenium = require("selenium-webdriver");
const By = selenium.By;

const driver = new selenium.Builder()
    .forBrowser("chrome")
    .build();

driver.get(process.env.URL);

//store By locators 
const locators = {
    inviteeForm: By.id("registrar"),
    inviteeNameField: By.name("name")
};

function addInvitee(name) {
    driver.findElement(locators.inviteeNameField)
        .sendKeys(name);

    driver.findElement(locators.inviteeForm).submit();
}

addInvitee("Jonathan Grieve");
addInvitee("Muhamed Hassan");
addInvitee("Steve Hunter");

There were no errors in the debug.log file and the new tab didn't crash. Success!!

Now, why would that be? What's the difference between using git bash in the integrated terminal in VS Code and using the standalone .exe file on Windows 10?

Appreciate any thoughts people have on this.

Jonathan Grieve , I had this working last week and after doing a Windows 10 update, it is no longer working. I'm just wondering specifically how you are running your code since you are having success. When I use Git Bash by itself with the same code above and this command

URL=http://port-80-m4qtmkkgh6.treehouse-app.com/ node index.js

Chrome crashes right after the page loads with a 'cannot focus element' error.

If I use the same command inside Visual Studio Code and Git Bash, it's not recognizing my Chromedriver PATH, even though I have it set in my environmental variables.

When you say you ran your code, are you using Visual Studio Code and Git Bash with the same command, or another way. Thank you.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Neil,

To be honest, I haven't really used Selenium since my Windows update last week. Let me do some tests right now.

One thing I didn't do was set the URL variable and run the script in the same command. But it looks like I'm running into problems too now. I can see that selenium is working and it's listening for tests but it seems there's a bug with the promise.js file.

DevTools listening on ws://127.0.0.1:12252/devtools/browser/64b9ff0b-7a45-48a3-a116-965671bae3f9
C:\xamp\htdocs\selenium\node_modules\selenium-webdriver\lib\promise.js:2626
        throw error;
        ^

WebDriverError: unknown error: 'url' must be a string

That's a shame. I'll have to dig deep again and see what the issue might be. I use the latest ChromeDriver, I'll have to see about updating Selenium

But to clarify i use

URL=https://url-i-want-to-test.com

node filename.js

as separate commands!

1 Answer

Thanks for your reply Jonathan. After I asked you my question last night, I restarted my computer to see if it would make a difference since I had recently added the Chromedriver and added it to my Environment PATH. It did fix the issue with Chrome crashing, but I was also getting a Promise error. I'll let you know if I figure anything out after work tonight.