forked from elgalu/selenium-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hola.py
58 lines (45 loc) · 1.69 KB
/
hola.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# To install the Python client library:
# pip install -U selenium
import time
import os
# Import the Selenium 2 namespace (aka "webdriver")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# http://selenium-python.readthedocs.org/en/latest/api.html
caps = DesiredCapabilities.CHROME
sel_host = os.environ.get('SEL_HOST','localhost')
sel_port = os.environ.get('SEL_PORT','4444')
myselenium = "http://%s:%s/wd/hub" % (sel_host, sel_port)
print ("Will connect to selenium at %s" % myselenium)
# http://selenium-python.readthedocs.org/en/latest/getting-started.html#using-selenium-with-remote-webdriver
driver = webdriver.Remote(command_executor=myselenium, desired_capabilities=caps)
time.sleep(0.5)
# Test: https://code.google.com/p/chromium/issues/detail?id=519952
pageurl = "http://www.google.com/adwords"
print ("Opening page %s" % pageurl)
driver.get(pageurl)
time.sleep(0.5)
print ("Current title: %s" % driver.title)
print ("Asserting 'Google Adwords' in driver.title")
assert "Google AdWords" in driver.title
pageurl = "http://www.python.org"
print ("Opening page %s" % pageurl)
driver.get(pageurl)
time.sleep(0.5)
print ("Asserting 'Python' in driver.title")
assert "Python" in driver.title
print ("Finding element by name: q")
elem = driver.find_element_by_name("q")
print ("Sending keys 'pycon'")
elem.send_keys("pycon")
time.sleep(0.5)
print ("Sending RETURN key")
elem.send_keys(Keys.RETURN)
print ("Ensure no results were found")
assert "No results found." not in driver.page_source
print ("Close driver and clean up")
driver.close()
time.sleep(0.5)
print ("All done. SUCCESS!")
driver.quit()