Home > Net >  Selenium opens chrome and shows error TypeError: 'str' object is not callable using Python
Selenium opens chrome and shows error TypeError: 'str' object is not callable using Python

Time:01-13

Im making an auth bot, but I faced with a problem! When Im trying to start my selenium bot, it opens few tabs in Chrome and do nothing. It also print that

"str" object is not callable

Can anyone solve it?

Terminal message:

PS E:*my path*1> & E:/Python/python.exe e:*my path*/1/main.py
e:*my path*1\main.py:32: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
self.browser = webdriver.Chrome(ChromeDriverManager().install(),options=options)

DevTools listening on ws://127.0.0.1:54545/devtools/browser/f9204f7e-ffbc-4ca1-b8f0-755537aba91f
Traceback (most recent call last):
  File "e:*my path*\1\main.py", line 76, in <module>
    bot.login()
TypeError: 'str' object is not callable
PS e:*my path*> [3484:9668:0113/153947.029:ERROR:device_event_log_impl.cc(215)] [15:39:47.028] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: ╧Ёшёюхфшэхээюх ъ ёшёЄхьх єёЄЁющёЄтю эх ЁрсюЄрхЄ. (0x1F)
[3484:9668:0113/153947.029:ERROR:device_event_log_impl.cc(215)] [15:39:47.029] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: ╧Ёшёюхфшэхээюх ъ ёшёЄхьх єёЄЁющёЄтю эх ЁрсюЄрхЄ. (0x1F)

P.S. I removed my main.py pathes in this error

My code:

class LoginBot():

  def __init__(self):
    #Excel reading
    wb = load_workbook('seo-fast_profiles.xlsx')
    sheet_ranges = wb['Work']
    self.login = sheet_ranges['A2'].value
    self.email = sheet_ranges['B2'].value
    self.passw = sheet_ranges['C2'].value

    #Optins and UserAgent
    user = UserAgent()
    options = webdriver.ChromeOptions()
    options.add_argument(user.random)
    self.browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)

  def close_browser(self):
    self.browser.close()
    self.browser.quit()

  def login(self):
    browser = self.browser
    browser.get("https://seo-fast.ru/login")
    time.sleep(random.randrange(1, 3))
    username_input = browser.find_element(By.ID, "logusername")
    username_input.clear()
    username_input.send_keys(self.email)
    time.sleep(1)
    username_input.send_keys(Keys.ENTER)
    time.sleep(2)
    password_input = browser.find_element(By.ID, "logpassword")
    password_input.send_keys(self.passw)
    time.sleep(5)
    password_input.send_keys(Keys.ENTER)
    time.sleep(7)
    #cookies
    pickle.dump(browser.get_cookies(), open(f"{self.login}_cookies", "wb"))

    self.close_browser()

  def xpath_exists(self, url):
    browser = self.browser
    try:
        browser.find_element(By.XPATH, url)
        exist = True
    except NoSuchElementException:
        exist = False
    return exist

bot = LoginBot()
bot.login()

Snapshot of browser opened chrome by selenium:

This is what selenium does

I tried to change bot.login to something else, bit it didnt work

CodePudding user response:

This error message...

PS E:*my path*1> & E:/Python/python.exe e:*my path*/1/main.py
e:*my path*1\main.py:32: DeprecationWarning: executable_path has been deprecated, please pass in a Service object

...indicates that the argument executable_path has been deprecated, instead you need to pass in a Service object


Solution

Effectively you need to replace:

self.browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)

with:

from selenium.webdriver.chrome.service import Service

self.browser = webdriver.Chrome(service=ChromeDriverManager().install(), options=options)
  • Related