2

I am using callow on a sandbox. I get these errors:

Traceback (most recent call last):
  File "C:\Users\Joe\callow\callow.py", line 163, in <module>
    wizard()
  File "C:\Users\Joe\callow\callow.py", line 93, in wizard
    brutes(username, username_selector, password_selector, submit_selector, pass_list, website)
  File "C:\Users\Joe\callow\callow.py", line 119, in brutes
    Sel_user = browser.find_element_by_css_selector(username_selector) # Finds Selector
AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'

Error originated from:

try:
        Sel_user = browser.find.element_by_css_selector(username_selector) # Finds Selector
    except selenium.common.exceptions.NoSuchElementException:
        print((color.RED + '\n[!]'+ color.CWHITE + ' Username feild selector is invalid.'))
        sys.stdout.flush()
        exit()
    try:
        Sel_pas = browser.find_element_by_css_selector(password_selector) # Finds Selector
    except selenium.common.exceptions.NoSuchElementException:
        print((color.RED + '\n[!]'+ color.CWHITE + ' Password feild selector is invalid.'))
        sys.stdout.flush()
        exit()
    try:
        enter = browser.find.element_by_css_selector(submit_selector) # Finds Selector
    except selenium.common.exceptions.NoSuchElementException:
        print((color.RED + '\n[!]'+ color.CWHITE + ' Login button selector is invalid.'))
        sys.stdout.flush()
        exit()

How can I fix this?

2 Answers 2

3

Since it mentions WebDriver, I'm assuming this is to do with Selenium? find_element_by_css_selector is deprecated, and if you were to use an IDE like PyCharm, it would tell you:

find_element_by_css_selector is deprecated. Please use find_element(by=By.CSS_SELECTOR, value=css_selector) instead

So instead of using find_element_by_css_selector, consider using:

Sel_user = browser.findElement(By.CSS_SELECTOR, username_selector)

Refer to the official documentation for more information: https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-css-selectors.

Sign up to request clarification or add additional context in comments.

1 Comment

For anybody reading this, the correct syntax for python is the following: browser.find_element(By.CSS_SELECTOR, username_selector)
1

Please don't forget to import the By object to access the CSS_SELECTOR property. I had to import the following to automate tasks in the Chrome browser.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

options = Options()
# options.add_experimental_option("detach", True)

driver = webdriver.Chrome(
    service=Service(ChromeDriverManager().install()),
     options=options
     )

driver.get("https://www.python.org/")
driver.maximize_window()

input = driver.find_element(By.CSS_SELECTOR,".documentation-widget p")

print(input)

driver.close()
driver.quit()

1 Comment

Dear god! Can there be more complexity?

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.