0

When I run the test, sometimes I got the the following error:

"(node:34959) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element:..."

And the test stops.

I want the test to going on and not to stop, but write a message into console.

My code now:

var one = await driver.findElement(By.xpath("//td[.='somethig']/following-sibling::td[1]/strong"));
var two = await one.getText();
await fs.appendFileSync("file.txt", two + ",");

How is it possible? Because I don't need this element, for further run. Thanks :)

1 Answers1

2

You only just need to wrap the error you need to log to console in try and catch.

let one = '';
let two = '';
try {
    one = await driver.findElement(By.xpath("//td[.='somethig']/following-sibling::td[1]/strong"));
    two = await one.getText();
} catch (error) {
    console.log(error);
}
await fs.appendFileSync("file.txt", two + ",");  
Tien Duong
  • 2,517
  • 1
  • 10
  • 27