0

I get this error:AttributeError: 'WebDriver' object has no attribute 'find_elemen_by_css_selector'

What is the current usage?

from selenium import webdriver


from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Chrome()

url = "http://github.com/"
driver.get(url)

search_input = driver.find_element("name", "q")

time.sleep(1)
search_input.send_keys("python")
time.sleep(3)
search_input.send_keys(Keys.ENTER)
time.sleep(1)
result = driver.find_elemen_by_css_selector(".repo-list-item h3 a")



for element in result:
    print(element)


driver.close()

3
  • it's just a typo. find_element_by... and not find_elemen_by... Commented Sep 16, 2022 at 7:23
  • it didn't work either Commented Sep 16, 2022 at 7:27
  • I'll write an answer to explain how to do it. Commented Sep 16, 2022 at 7:30

4 Answers 4

1

Looks like you forgot a t

driver.find_element_by_css_selector(".repo-list-item h3 a")
Sign up to request clarification or add additional context in comments.

Comments

1

You have missing t in the below line at elemen

result = driver.find_elemen_by_css_selector(".repo-list-item h3 a")

so the correct line is :

result = driver.find_element_by_css_selector(".repo-list-item h3 a")

Comments

0

You can do this:

from selenium.webdriver.common.by import By

result = driver.find_element(By.CSS_SELECTOR, '.repo-list-item h3 a')

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-1

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.