lea automan
lea automan

Reputation: 1

selenium with python, how to handle two text field in alert box?

I am new in selenium with python and still in practice

selenium with python, may I how to handle two text field in alert box? I did search on Google and some pages mention to using javascriptexecutor but I don't know how's it work and xpath is not working? thank you

Blockquote

Info website: https://the-internet.herokuapp.com/basic_auth

Both username and password is admin

Here is my code below:

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions() options.add_experimental_option("detach", True) driver = webdriver.Chrome(options=options) driver.maximize_window() driver.get("https://the-internet.herokuapp.com/basic_auth")

promptAlertUsername = WebDriverWait(driver, 10).until(EC.presence_of_element_located()) promptAlertUsername.sendKeys("admin")

promptAlertPassword = WebDriverWait(driver, 10).until(EC.presence_of_element_located()) promptAlertPassword.sendKeys("admin")

time.sleep(2) driver.quit()

Upvotes: 0

Views: 162

Answers (1)

Yaroslavm
Yaroslavm

Reputation: 4804

This is Basic Http Authentication modal. The easiest way to handle it - using simple link syntax https://login:password@url.

In your case you can login via

url = "https://admin:[email protected]/basic_auth"
driver.get(url)

or

login = 'admin'
password = 'admin'
url = f"https://{login}:{password}@the-internet.herokuapp.com/basic_auth"
driver.get(url)

Upvotes: 1

Related Questions