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 Sub Pages are Pages, Too!

Shane Moulton
Shane Moulton
10,538 Points

Arrow Function not working throwing back unable to locate errors

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

class HomePage {
    constructor(driver){
        this.driver = driver;
        this.locators = {
            inviteeForm: By.id("registrar"),
            inviteeNameField: By.css("#registrar input[name='name']"),
            toogleVisibility: By.css(".main > div input"),
            inviteeByName: name => By.xpath(`//span[text() = "${name}"]/..`)
        };
    }
    open(){
        this.driver.get(process.env.URL);
    }

    addInvitee(name) {
        this.driver.findElement(this.locators.inviteeNameField).sendKeys(name);
         this.driver.findElement(this.locators.inviteeForm).submit();
}

 toogleVisibility(){
    this.driver.findElement(this.locators.toogleVisibility).click();
}

findInviteeByName(name){
    const el = this.driver.findElement(this.locators.inviteeByName(name));
        return new Invitee(el);
 }
}

class Invitee{
    constructor(element){
        this.element = element;
        this.locators = {
            removeButton: By.css('button:last-child'),
            confirmedCheckbox: By.css("input[type='checkbox']")
        };
    }
    remove(){
        this.element.findElement(this.locators.removeButton).click();
    }

    toggleConfirmation(){
        this.element.findElement(this.locators.confirmedCheckbox).click();
    }
}

module.exports = HomePage
node:939) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method"
:"xpath","selector":"//span[text() = "David Riesz"]/.."}  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.11.6 x86_64)
    at Object.checkLegacyResponse (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/error.js:5
85:15)
    at parseHttpResponse (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/http.js:533:13)
    at Executor.execute (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/http.js:468:26)    at <anonymous>    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:939) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reje
ction id: 1)
(node:939) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejectio
ns that are not handled will terminate the Node.js process with a non-zero exit code.(node:939) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method"
:"xpath","selector":"//span[text() = "Jennifer Nordell"]/.."}
  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.11.6 x86_64)
    at Object.checkLegacyResponse (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/error.js:5
85:15)    at parseHttpResponse (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/http.js:533:13)    at Executor.execute (/Users/shanemoulton/selenium-basics/node_modules/selenium-webdriver/lib/http.js:468:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)(node:939) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing in
side of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reje
ction id: 2)

Moderator edited: Markdown added so that code renders properly in the forums. -jn

Same error here.

Dylan Meares
Dylan Meares
6,323 Points

I'm having the same issue described here. Is there setup missing? Is the test website broken?

Hi, has anyone come up with an answer to this? Jonathan Grieve I wonder if you can help as I can see you are a Treehouse Moderator? I am currently stuck on this same issue..

I have managed to get this working now. Your code looks right so I have no idea what you're doing wrong but I managed to figure it out by watching this series over and over.