-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths02b_run_test_full.py
executable file
·48 lines (33 loc) · 1.32 KB
/
s02b_run_test_full.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
#!/usr/bin/env python2.7
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
browsers = [DesiredCapabilities.CHROME, DesiredCapabilities.FIREFOX]
for browser in browsers:
##region init webdriver object
SELENIUM_HUB = 'http://localhost:4444/wd/hub'
from selenium import webdriver
driver = webdriver.Remote(
command_executor=SELENIUM_HUB,
desired_capabilities=browser,
)
##endregion init webdriver object
##region do we scraping
#go to the google home page
driver.get('http://www.google.com')
#the page is ajax so the title is originally this:
print(driver.title)
#find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name('q')
#type in the search
inputElement.send_keys('cheese!')
#submit the form (although google automatically searches now without submitting)
inputElement.submit()
try:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#we have to wait for the page to refresh, the last thing that seems to be updated is the title
WebDriverWait(driver, 10).until(EC.title_contains('cheese!'))
#You should see 'cheese! - Google Search'
print(driver.title)
finally:
driver.quit()
##endregion do we scraping