Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press ENTER key in Selenium WebDriver with java when element property not present

I am using selenium webdriver with Java to automate the webpages

When I enter the url, I am getting the authentication required dialog box

I am able to enter the username and password by configuring profile but I am not able to click on OK button

Note: Not able to get the ok button property so am not able to use the below code

import org.openqa.selenium.Keys
WebElement.sendKeys(Keys.RETURN);

Is there any other way to press on ok button through webdriver?

like image 471
Santhosh Chandrashekar Avatar asked Jan 18 '26 23:01

Santhosh Chandrashekar


1 Answers

You need to handle it as an alert box, wait for popup to appear and click OK.

Below code waits up to a maximum of 10 seconds for the popup to be present and then accepts it by clicking OK. Although wait is optional.

new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
like image 166
LINGS Avatar answered Jan 20 '26 12:01

LINGS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!