-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_org_search.py
executable file
·39 lines (27 loc) · 1.36 KB
/
python_org_search.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# https://selenium-python.readthedocs.io/getting-started.html
# The selenium.webdriver module provides all the WebDriver implementations.
# Currently supported WebDriver implementations are Firefox, Chrome, IE and Remote.
from selenium import webdriver
# The Keys class provide keys in the keyboard like RETURN, F1, ALT etc.
from selenium.webdriver.common.keys import Keys
# provides useful methods for interacting HTML <select> element
from selenium.webdriver.support.ui import Select
# Next, the instance of Firefox WebDriver is created.
driver = webdriver.Firefox()
# The driver.get method will navigate to a page given by the URL
driver.get("http://www.python.org")
# The next line is an assertion to confirm that title has “Python” word in it:
assert "Python" in driver.title
# the input text element can be located by its name attribute using find_element_by_name method
elem = driver.find_element_by_name("q")
# To be safe, we’ll first clear any prepopulated text in the input field
# (e.g. “Search”) so it doesn’t affect our search results:
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
# After submission of the page, you should get the result if there is any.
# To ensure that some results are found, make an assertion:
assert "No results found." not in driver.page_source
driver.close()