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 A Fork in the XPath

Ryan Giusti
Ryan Giusti
18,082 Points

Unhandled promised rejection

Getting the following errors Xpath selector error: NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()="Shadd Anderson"]/../button[last()]"}

Been seeing this one throughout the course: 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(). (rejection id: 1) (node:12324) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Looked to the community, no answer. Disappointing to see others with similar/same issues unaddressed.

2 Answers

Carrie Happoldt
Carrie Happoldt
15,160 Points

Here is my solution:

setTimeout(function(){ removeInvitee("Shadd Anderson"); }, 10000);

Since the issue is with async - I had the removeInvitee() function wait 10 seconds before running. This allowed time for chrome to start up and add all of the invitees. Once "Shadd Anderson" was actually there, the removeInvitee() could then remove the name.

Also I used removeButtonForInvitee: invitee => By.xpath(//span[text()="${invitee}"]/../button[2])

Hope this helps! Good Luck

Heath Hughes
Heath Hughes
19,766 Points

Thanks, Carrie Happoldt worked like a charm! I banged my head against a wall waaay too long before checking the questions here.

Irina Piliugina
Irina Piliugina
8,678 Points

thanks! it really has worked!

After some research, found an alternative way by using wait until.

function removeInvitee(invitee){ found = driver.wait(selenium.until.elementLocated(locators.removeButtonForInvitee(invitee)),10000); found.click(); }