Fill username and password using selenium in python
Docs: https://selenium-python.readthedocs.io/navigating.html
For versions 4.3.0 (released in June 2022) and later, calls to find_element_by_*
and find_elements_by_*
were removed from Selenium. You need to use the new API:
from selenium.webdriver.common.by import By
driver = webdriver.Firefox(...) # Or Chrome(), or Ie(), or Opera()
# To catch <input type="text" id="passwd" />
password = driver.find_element(By.ID, "passwd")
# To catch <input type="text" name="passwd" />
password = driver.find_element(By.NAME, "passwd")
password.send_keys("Pa55worD")
driver.find_element(By.NAME, "submit").click()
The original response, for API versions 4.2.0 or previous:
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()
A note to your code: Select()
is used to act on a Select Element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select).
Selenium click not working in Chrome
This is what i tried on my local system and it worked
from selenium.webdriver.common.by import By
from selenium import webdriver
driver = webdriver.Chrome(executable_path="D:\\cs\\chromedriver.exe")
driver.get("https://www.instagram.com/")
a=driver.find_element(By.XPATH,'//a[text() = "Log in"]')
# added this step for compatibility of scrolling to the view
driver.execute_script("return arguments[0].scrollIntoView();", a)
a.click()
Corrected the XPATH and other changes.Please note executable path should be replaced with your path.
Related Topics
Python Multiprocessing on Windows, If _Name_ == "_Main_"
When I Catch an Exception, How to Get the Type, File, and Line Number
Format Floats with Standard JSON Module
Keyerror: 'Tcl_Library' When I Use Cx_Freeze
How to Color Python Logging Output
Add X and Y Labels to a Pandas Plot
Plot with Custom Text for X Axis Points
How to Change Index of a for Loop
How to Find Out the Number of Cpus Using Python
Reading a Text File and Splitting It into Single Words in Python
Check If a String in a Pandas Dataframe Column Is in a List of Strings
Ssl.Sslerror: Tlsv1 Alert Protocol Version
What Do the Python File Extensions, .Pyc .Pyd .Pyo Stand For
Appending a Dictionary to a List - I See a Pointer Like Behavior