Skip to content

Instantly share code, notes, and snippets.

@savex83
Forked from aaira-a/google.py
Created April 22, 2020 06:29
Show Gist options
  • Save savex83/4e5f500f627b52bd42af491e4c3207f6 to your computer and use it in GitHub Desktop.
Save savex83/4e5f500f627b52bd42af491e4c3207f6 to your computer and use it in GitHub Desktop.
python selenium google search example
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("http://www.google.com")
input_element = driver.find_element_by_name("q")
input_element.send_keys("python")
input_element.submit()
RESULTS_LOCATOR = "//div/h3/a"
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, RESULTS_LOCATOR)))
page1_results = driver.find_elements(By.XPATH, RESULTS_LOCATOR)
for item in page1_results:
print(item.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment