Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02916f7

Browse files
committed
add automate login using selenium tutorial
1 parent14a61d6 commit02916f7

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
9797
-[How to Extract All PDF Links in Python](https://www.thepythoncode.com/article/extract-pdf-links-with-python). ([code](web-scraping/pdf-url-extractor))
9898
-[How to Extract Images from PDF in Python](https://www.thepythoncode.com/article/extract-pdf-images-in-python). ([code](web-scraping/pdf-image-extractor))
9999
-[Automated Browser Testing with Edge and Selenium in Python](https://www.thepythoncode.com/article/automated-browser-testing-with-edge-and-selenium-in-python). ([code](web-scraping/selenium-edge-browser))
100+
-[How to Automate Login using Selenium in Python](https://www.thepythoncode.com/article/automate-login-to-websites-using-selenium-in-python). ([code](web-scraping/automate-login))
100101

101102
-###[Python Standard Library](https://www.thepythoncode.com/topic/python-standard-library)
102103
-[How to Transfer Files in the Network using Sockets in Python](https://www.thepythoncode.com/article/send-receive-files-using-sockets-python). ([code](general/transfer-files/))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[How to Automate Login using Selenium in Python](https://www.thepythoncode.com/article/automate-login-to-websites-using-selenium-in-python)
2+
To run this:
3+
-`pip3 install -r requirements.txt`
4+
- Get[ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/home) and put it in the current directory.
5+
- Edit credentials in`automate_login.py` and run it!
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
fromloggingimporterror
2+
fromseleniumimportwebdriver
3+
fromselenium.webdriver.support.uiimportWebDriverWait
4+
5+
# Github credentials
6+
username="username"
7+
password="password"
8+
9+
# initialize the Chrome driver
10+
driver=webdriver.Chrome(r"C:\Users\STRIX\Desktop\selenium\chromedriver")
11+
# head to github login page
12+
driver.get("https://github.com/login")
13+
# find username/email field and send the username itself to the input field
14+
driver.find_element_by_id("login_field").send_keys(username)
15+
# find password input field and insert password as well
16+
driver.find_element_by_id("password").send_keys(password)
17+
# click login button
18+
driver.find_element_by_name("commit").click()
19+
# wait the ready state to be complete
20+
WebDriverWait(driver=driver,timeout=10).until(
21+
lambdax:x.execute_script("return document.readyState === 'complete'")
22+
)
23+
error_message="Incorrect username or password."
24+
# get the errors (if there are)
25+
errors=driver.find_elements_by_class_name("flash-error")
26+
# print the errors optionally
27+
# for e in errors:
28+
# print(e.text)
29+
# if we find that error message within errors, then login is failed
30+
ifany(error_messageine.textforeinerrors):
31+
print("[!] Login failed")
32+
else:
33+
print("[+] Login successful")
34+
35+
# close the driver
36+
driver.close()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
selenium

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp