Recently ventured into the realm of Selenium through "Mozilla MDN web docs" and encountered a stumbling block with an error. Seeking assistance to overcome this hurdle.
Attempting to retrieve text attributes of elements like p, title, alert... but facing obstacles in achieving it.
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://mdn.github.io/learning-area/tools-testing/cross-browser-testing/accessibility/native-keyboard-accessibility.html');
var button = driver.findElement(By.css('button:nth-of-type(1)'));
button.click();
var alert = driver.switchTo().alert();
alert.getText().then(function(text) {
console.log('Alert text is \'' + text + '\'');
})
alert.accept();
uptimizators-MacBook-Air:study uptimizator$ node quick_test
(node:1941) UnhandledPromiseRejectionWarning: NoSuchAlertError: no such alert
(Session info: chrome=78.0.3904.97)
at Object.throwDecodedError (/Users/uptimizator/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/Users/uptimizator/node_modules/selenium-webdriver/lib/http.js:563:13)
at Executor.execute (/Users/uptimizator/node_modules/selenium-webdriver/lib/http.js:489:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async thenableWebDriverProxy.execute (/Users/uptimizator/node_modules/selenium-webdriver/lib/webdriver.js:699:17)
(node:1941) 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:1941) [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.
(node:1941) UnhandledPromiseRejectionWarning: NoSuchAlertError: no such alert
(Session info: chrome=78.0.3904.97)
at Object.throwDecodedError (/Users/uptimizator/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/Users/uptimizator/node_modules/selenium-webdriver/lib/http.js:563:13)
at Executor.execute (/Users/uptimizator/node_modules/selenium-webdriver/lib/http.js:489:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async thenableWebDriverProxy.execute (/Users/uptimizator/node_modules/selenium-webdriver/lib/webdriver.js:699:17)
(node:1941) 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: 2)