Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99410

Watir::Exception::UnknownObjectException: unable to locate alert

$
0
0

Watir::Exception::UnknownObjectException: unable to locate alert

I get this exception while trying to get value from alert using the below code.

alert_text = $browser.alert.text

I am running on headless chrome driver with Google Chrome 79.0.3945.88 in CentOS Linux release 7.4.1708 (Core)

The same code works in windows with headless chrome and normal chrome browser.

Then I wrote the below code as an alternative to the default JS alert.

$browser.execute_script('window.alert = function(sMessage) {
                alert_text = sMessage;

            };')

This has been mentioned in Watir website and on some StackOverflow answers.

That's to capture the alert text and below code to return the alert text to pass the test case.

alert_text = $browser.execute_script("return alert_text")

But it gave

javascript error: alert_text is not defined

I observed that the function which was written to override the default alert was never called. How to solve this.

I either need the alert in the headless browser or a way to capture the alert message at least.


Viewing all articles
Browse latest Browse all 99410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>