Не удалось найти ошибку элемента в селене webdriver node.js - PullRequest
0 голосов
/ 02 ноября 2019

Я поместил условие if else в selenium webdriver node.js, чтобы проверить, содержит ли строка строку «Добавить новую», но я получаю ошибку Unable to locate element: // *[contains(text(),'Add New')]

Вот код:

    if (driver.findElement(By.xpath("// *[contains(text(),'Add New')]"))) {
        reject(new Error("This is an error"));
    } else {
        resolve(true);
    }

1 Ответ

1 голос
/ 02 ноября 2019

Попробуйте это

 string bodyText = driver.findElement(By.xpath("//body")).text;
 if (bodyText.Contains('Add New')) {
      reject(new Error("This is an error"));
  } else {
      resolve(true);
  }

Или

try {
    driver.findElement(By.xpath("// *[contains(text(),'Add New')]"));
    reject(new Error("This is an error"));
}
catch (ElementNotFound e) {
    resolve(true);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...