Issue
When I manually open a browser, both firefox and chrome, and proceed to a website where I previously saved my login credentials via the browser, the username and password fields automatically populate as they should. However, when I use the python selenium webdriver to open the browser to a specific page, the fields do not populate.
The point of my script is to open the webpage and use element.submit()
to login since the login credentials should already be populated., but the are NOT.
How can i get them to populate in the fields?
For Example:
driver = webdriver.Chrome()
driver.get("https://facebook.com")
element = driver.find_element_by_id("u_0_v")
element.submit()
Solution
This is because selenium doesn't use your default browser instance, it opens a different instance with a temporary (empty) profile.
If you would like it to load a default profile you need to instruct it to do so.
Here's a chrome example:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)
And here's a firefox example:
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile
profile = FirefoxProfile("C:\\Path\\to\\profile")
driver = webdriver.Firefox(profile)
Here we go, just dug up a link to this in the (unofficial) documentation. Firefox Profile and the Chrome driver info is right underneath it.
Answered By - bmcculley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.