Skip to content

Commit 1999f10

Browse files
committed
Adiciona ao repositorio arquivo que testa se o headless browser funciona
1 parent b8a5e37 commit 1999f10

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

test-headless-browser.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from selenium.webdriver import Chrome
2+
from selenium.webdriver.chrome.options import Options
3+
4+
from selenium.common.exceptions import NoSuchElementException
5+
6+
# try:
7+
# pass
8+
# except NoSuchElementException as e:
9+
# print(e)
10+
11+
# Creating a headless browser:
12+
opts = Options()
13+
opts.set_headless()
14+
assert opts.headless # Operating in headless mode
15+
browser = Chrome(options=opts)
16+
browser.get('https://duckduckgo.com')
17+
18+
19+
# Querying the DOM
20+
search_form = browser.find_element_by_id('search_form_input_homepage')
21+
search_form.send_keys('real python')
22+
search_form.submit()
23+
24+
25+
# Printing the results:
26+
results = browser.find_elements_by_class_name('result')
27+
print(results[0].text)
28+
29+
browser.close()
30+
quit()

0 commit comments

Comments
 (0)