-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaula_04_b.py
More file actions
92 lines (57 loc) · 1.91 KB
/
aula_04_b.py
File metadata and controls
92 lines (57 loc) · 1.91 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
80
81
82
83
84
85
86
87
88
89
90
91
92
# Aula 04 B Atributos e Navegação
from selenium.webdriver import Firefox
from time import sleep
def find_by_text(browser, tag, text):
"""
Encontrar o elemento com texto 'text'
Args:
browser: Instância do browser [Firefox, chrome],
text: [conteudo que deve está na tag],
tag: Onde o texto será procurado
"""
elementos = browser.find_elements_by_tag_name(tag) # lista
for elemento in elementos:
if elemento.text in text:
return elemento
browser = Firefox()
browser.get('http://selenium.dunossauro.live/aula_04_b.html')
textos = ['um', 'dois', 'tres', 'quatro']
for t in textos:
find_by_text(browser, 'div', t).click()
for t in textos:
sleep(2)
browser.back()
for t in textos:
sleep(2)
browser.forward()
'''from selenium.webdriver import Firefox
from time import sleep
def find_by_text(navegador, tag, text):
"""Encontrar o elemento com o texto `text`
Argumentos:
- navegador = Instancia do browser [firefox, chrome,...]
- text = conteudo que deve está na tag
- tag = tag onde o texto será procurado
"""
elementos = navegador.find_elements_by_tag_name(tag)
for elemento in elementos:
if elemento.text == text:
return elemento
navegador = Firefox(executable_path='geckodriver.exe')
url = 'https://selenium.dunossauro.live/aula_04_b.html'
navegador.get(url)
# elemento = find_by_text(navegador, 'div', 'um').click()
nome_das_caixas = ['um', 'dois', 'tres', 'quatro']
for texto in nome_das_caixas:
find_by_text(navegador, 'div', texto).click()
# Voltar
for texto in nome_das_caixas:
sleep(0.3)
navegador.back()
for b in range(4):
sleep(2)
navegador.back()
# Pra frente novamente
for texto in nome_das_caixas:
sleep(0.3)
navegador.forward()'''