Skip to content

Instantly share code, notes, and snippets.

@aaira-a
Created April 8, 2016 00:54
Show Gist options
  • Save aaira-a/32b89944b98a3fd79d44ebfdac16b63d to your computer and use it in GitHub Desktop.
Save aaira-a/32b89944b98a3fd79d44ebfdac16b63d 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)
@mjhiremath
Copy link

RESULTS_LOCATOR = "//div/h3/a" , How did you find this? This is not working for me.

from Selenium import login
import time
from selenium.webdriver.common.keys import Keys
import selenium.webdriver.support.expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By

login.open_broweser()
ele = login.driver.find_element_by_name("q")
ele.send_keys("python")
#ele.send_keys(Keys.ARROW_DOWN)
#ele.send_keys(Keys.ARROW_DOWN)
#time.sleep(10)
#ele.send_keys(Keys.RETURN)
ele.submit()

RESULTS_LOCATOR = "//div/h3/a"

WebDriverWait(login.driver, 10).until(
EC.visibility_of_element_located((By.XPATH, RESULTS_LOCATOR)))

page1_results = login.driver.find_elements(By.XPATH, RESULTS_LOCATOR)

for item in page1_results:
print(item.text)

@chlenc
Copy link

chlenc commented May 30, 2021

автор, че за игнор ебаный?

@browneye1826
Copy link

автор, че за игнор ебаный?

Does the author work for you? #TypicalRussian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment