-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathE4_buscando_xpath.py
More file actions
33 lines (24 loc) · 966 Bytes
/
E4_buscando_xpath.py
File metadata and controls
33 lines (24 loc) · 966 Bytes
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
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
class usando_unittest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox(executable_path = "./geckodriver")
def test_buscar_por_xpath(self):
driver = self.driver
driver.get("https://www.google.com")
buscar_por_xpath = driver.find_element_by_xpath("//*[@id='tsf']/div[2]/div[1]/div[1]/div/div[2]/input")
buscar_por_xpath.send_keys("selenium")
buscar_por_xpath.send_keys(Keys.ARROW_DOWN)
buscar_por_xpath.send_keys(Keys.ARROW_DOWN)
sleep(3)
buscar_por_xpath.send_keys(Keys.RETURN)
sleep(3)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
#xpath = una estructura de objetos
#xpath relativo: //*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input
#xpath absoluto: