T
T
tehnazavr2018-08-07 15:58:53
Automation
tehnazavr, 2018-08-07 15:58:53

How to wait for an alert to appear on a page using selenium webdriver in javascript?

There is a page. When you switch to it, alert may appear, or it may not. I want to make an implementation so that when going to the page, the driver waits for 5 seconds for alert, and if it does not appear, then continue the test further. I found several implementations for various languages, but they did not work on js.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Glukhovtsev, 2018-08-09
@valera-glukhovtsev

Try like this:

try {
  Thread.sleep(5000);\\Ждём пять секунд
} catch (InterruptedException e) {
}

if (driver.switchTo().alert() != null) {
  \\Если алерт есть, делаем то-то...
}

\\...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question