0

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()

2

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.