How can I auto fill the username and password over the link below:
from selenium import webdriver from selenium.webdriver.common.keys import Keys chromedriver = 'C:\\chromedriver.exe' browser = webdriver.Chrome(chromedriver) browser.get('http://www.example.com')
After that I really do not know:
username = Select(browser.find_element_by_name('Username')) password = Select(browser.find_element_by_name('Password')) username.select_by_visible_text("text") password.select_by_visible_text("text")
alert(); //Selenium-WebDriver Java Code for entering Username & Password as below: driver. findElement(By.id("userID")). sendKeys("userName"); driver. findElement(By.id("password")).
To handle the basic authentication popup, we can pass the username and password along with the web page's URL. When the login pop-up is prompted, we enter the username as “admin” and the password as “admin” and then login. Thus, the user would be successfully logged into the website.
Passing username and password in the URL helps to avoid the login prompt. This is achieved by encoding the username and password in the URL, that is, prepending username:password@ to the hostname in the URL.
driver = webdriver.Firefox(...) # Or Chrome(), or Ie(), or Opera() username = driver.find_element_by_id("username") password = driver.find_element_by_id("password") username.send_keys("YourUsername") password.send_keys("Pa55worD") driver.find_element_by_name("submit").click()
Notes to your code:
find_element_by_name('Username')
: Username
capitalized doesn't match anything.Select()
is used to act on a Select Element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)Use WebElement.send_keys
method to simulate key typing.
name
in the code (Username
, Password
) does not match actual name
of the elements (username
, password
).
username = browser.find_element_by_name('username') username.send_keys('user1') password = browser.find_element_by_name('password') password.send_keys('secret') form = browser.find_element_by_id('loginForm') form.submit() # OR browser.find_element_by_id('submit').click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With