-
Notifications
You must be signed in to change notification settings - Fork 24
/
selenium-example.py
35 lines (27 loc) · 942 Bytes
/
selenium-example.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
import click
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
@click.command()
@click.argument("location")
@click.argument("screenshot_filename", type=click.Path(exists=False))
def main(location, screenshot_filename):
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("https://maps.google.com")
search_box = driver.find_element(By.ID, "searchboxinput")
search_box.clear()
search_box.send_keys(location)
search_box.send_keys(Keys.RETURN)
body = driver.find_element(By.TAG_NAME, "body")
body.send_keys(Keys.ADD)
body.send_keys(Keys.ADD)
minimap = driver.find_element(By.ID, "minimap")
buttons = minimap.find_elements(By.TAG_NAME, "button")
buttons[2].click()
time.sleep(2)
driver.save_screenshot(screenshot_filename)
driver.quit()
if __name__ == "__main__":
main()