Skip to content

Commit aac8641

Browse files
committed
update login automation tutorial
1 parent 0f881a9 commit aac8641

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

web-scraping/automate-login/automate_login.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
# head to github login page
1212
driver.get("https://github.com/login")
1313
# find username/email field and send the username itself to the input field
14-
driver.find_element_by_id("login_field").send_keys(username)
14+
driver.find_element("id", "login_field").send_keys(username)
1515
# find password input field and insert password as well
16-
driver.find_element_by_id("password").send_keys(password)
16+
driver.find_element("id", "password").send_keys(password)
1717
# click login button
18-
driver.find_element_by_name("commit").click()
18+
driver.find_element("name", "commit").click()
1919
# wait the ready state to be complete
2020
WebDriverWait(driver=driver, timeout=10).until(
2121
lambda x: x.execute_script("return document.readyState === 'complete'")
2222
)
2323
error_message = "Incorrect username or password."
2424
# get the errors (if there are)
25-
errors = driver.find_elements_by_class_name("flash-error")
25+
errors = driver.find_elements("css selector", ".flash-error")
2626
# print the errors optionally
2727
# for e in errors:
2828
# print(e.text)
@@ -32,5 +32,13 @@
3232
else:
3333
print("[+] Login successful")
3434

35+
# an example scenario, show me my public repositories
36+
repos = driver.find_element("css selector", ".js-repos-container")
37+
# wait for the repos container to be loaded
38+
WebDriverWait(driver=driver, timeout=10).until((lambda x: repos.text != "Loading..."))
39+
# iterate over the repos and print their names
40+
for repo in repos.find_elements("css selector", "li.public"): # you can use "li.private" for private repos
41+
print(repo.find_element("css selector", "a").get_attribute("href"))
42+
3543
# close the driver
3644
driver.close()

0 commit comments

Comments
 (0)