Omkommersind
Omkommersind

Reputation: 295

Sending "Enter" key to browser window

I'm looking for an opportunity to send "Enter" key to browser window, not to web element(to confirm the appearing save dialog). Is it possible?

Upvotes: 1

Views: 3608

Answers (1)

Brydenr
Brydenr

Reputation: 798

This is in python, but other language will be similar. You should be able to use driver.switch_to.alert when the alert appears, which returns the alert object. If you just want to confirm the alert, use driver.switch_to.alert.accept(). Sending the enter key would be:

from selenium.webdriver.common.keys import Keys

# Get to stage where alert appears
# Send enter key
driver.switch_to.alert.send_keys(Keys.ENTER)

You may need to use Expected Conditions to wait for the alert to actually appear.

Upvotes: 1

Related Questions