-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecord_via_webdriver.py
56 lines (41 loc) · 1.44 KB
/
record_via_webdriver.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
#!/usr/bin/env python
"""
To use this script you need to install selenium:
* pip install selenium
And put the chromedriver on your PATH:
http://code.google.com/p/selenium/wiki/ChromeDriver
Extension:
Make sure to update the path to the webscript extension.
It needs to be packaged extension.
"""
from selenium import webdriver
PATH_TO_EXT = '/Users/king/proj/webscript.crx'
def main(url, webscript_ext):
co = webdriver.ChromeOptions()
co.add_extension(webscript_ext)
driver = webdriver.Chrome(chrome_options=co)
# Grab replay window
driver.switch_to_window(driver.window_handles[1])
# Grab useful buttons
start = driver.find_element_by_id('start')
stop = driver.find_element_by_id('stop')
replay = driver.find_element_by_id('replay')
# Start recording
start.click()
# Grab the newly created window
driver.switch_to_window(driver.window_handles[2])
driver.set_window_size(800, 600)
# Switch to main window
driver.switch_to_window(driver.window_handles[0])
###########################################
# Script to driving navigation of webpage
driver.get(url)
search = driver.find_element_by_name("q")
search.send_keys("Wow")
search.submit()
###########################################
# Stop Recording
driver.switch_to_window(driver.window_handles[1])
stop.click()
if __name__ == '__main__':
main('http://www.google.com/', PATH_TO_EXT)