So, here it is.
I am not sure what you're trying to achieve with this code, I printed the href of every result.
Well, you can try the code, understand it and modify it as you like.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("http://github.com/")
search_input = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, "//input[@name='q']")))
search_input.send_keys("python")
search_input.send_keys(Keys.ENTER)
result = WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.XPATH, "//a[@class='v-align-middle']")))
for element in result:
print(element.get_attribute("href"))
driver.close()
Note that I've used explicit waits instead of the less performant time.sleep().
I also personally prefer to locate elements by XPath but of course you can do it by CSS selector if you want.
If it helped please mark the answer as accepted :)
find_element_by...and notfind_elemen_by...