-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.py
More file actions
79 lines (62 loc) · 2.42 KB
/
github.py
File metadata and controls
79 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from selenium import webdriver
from time import sleep
class ChromeAuto:
def __init__(self):
self.driver_path = 'chromedriver.exe'
self.options = webdriver.ChromeOptions()
self.options.add_argument('user-data-dir=Perfil')
self.chrome = webdriver.Chrome(
self.driver_path,
options=self.options
)
def clica_sign_in(self):
try:
btn_sign_in = self.chrome.find_element_by_link_text('Sign in')
btn_sign_in.click()
except Exception as e:
print('Erro ao clicar em Sign in:', e)
def acessa(self, site):
self.chrome.get(site)
def sair(self):
self.chrome.quit()
def clica_perfil(self):
try:
perfil = self.chrome.find_element_by_css_selector(
'body > div.position-relative.js-header-wrapper > header > div.Header-item.position-relative.mr-0.d-none.d-lg-flex > details')
perfil.click()
except Exception as e:
print('Erro ao clicar no perfil:', e)
def faz_logout(self):
try:
perfil = self.chrome.find_element_by_css_selector(
'<body > div.position-relative.js-header-wrapper > header > div.Header-item.position-relative.mr-0.d-none.d-lg-flex > details > details-menu > form > button')
perfil.click()
except Exception as e:
print('Erro fazer logout:', e)
def verifica_usuario(self, usuario):
profile_link = self.chrome.find_element_by_class_name(
'user-profile-link')
profile_link_html = profile_link.get_attribute('innerHTML')
assert usuario in profile_link_html
def faz_login(self):
try:
input_login = self.chrome.find_element_by_id('login_field')
input_password = self.chrome.find_element_by_id('password')
btn_login = self.chrome.find_element_by_name('commit')
input_login.send_keys('') #email da conta github
input_password.send_keys('') #senha
sleep(3)
btn_login.click()
except Exception as e:
print('Erro ao fazer login:', e)
if __name__ == '__main__':
chrome = ChromeAuto()
chrome.acessa('https://github.com/')
chrome.clica_perfil()
chrome.faz_logout()
chrome.clica_sign_in()
chrome.faz_login()
chrome.clica_perfil()
chrome.verifica_usuario('') #usuário github
sleep(5)
chrome.sair()