0

login.php calls the following function when submitted

<script type="text/javascript"> function validate(){ var res=confirm("Are you sure"); if(res) return true; else return false; } </script> 

I am trying to login through a python script using Selenium. When I click login the following script is called and I need to select 'yes' to login.

from selenium import webdriver from selenium.webdriver.common.keys import Keys browser = webdriver.Firefox() browser.get("webpage/login.php") username = browser.find_element_by_id("id") password = browser.find_element_by_id("pass") username.send_keys("username") password.send_keys("password") login_attempt = browser.find_element_by_xpath("//*[@type='submit']") login_attempt.submit() #I want to send yes to the `validate` function and the #then then again do browser.get("webpage/home.php") to scrape info from a html tag #print(login_attempt.submit()) 

I am relatively new to what I am trying to do .. suggestions are well received if there are better practices.

2

2 Answers 2

1

The pop up come out after click submit, we call them JS alert/confirm, they trigger by JavaScript and supported natively by browser. For such pop-up, selenium had already implement the code to interact with them. So just to find the methond from selenium python client API on the version you used. (The methond name and how to call maybe not same in different client API version).

alert = browser.switch_to_alert() //accept the alert alert.accept() // maybe as below to call alert = driver.switch_to.alert alert.accept() // or Alert(driver).accept() 
4
0

Use following code:

browser = webdriver.Firefox() browser.get("http://username:password@webpage/login.php") 

you will be able to bypass this authentication alert.

0

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.