-1

I am having problems with my types and would be really glad if you could help me. I am downloading a captcha using

captcha = self.chrome_driver.driver.find_element_by_xpath(captcha_xpath).screenshot_as_png

which according the documentation: saves the screenshot of the current element as a binary data. Then i want to send it to twocaptcha function normal(captcha, caseSensitive=True) which according to the documentation takes image or base64. So when i run the function i get error

TypeError: a bytes-like object is required, not 'str The type of captcha is <class 'bytes'>

How to convert the captcha to base64 or image in order to make it work.

Emil
  • 7
  • 3

1 Answers1

0

Why not simply replace your .screeshot_as_png with .screenshot_as_base64() per the list of methods here.

get_screenshot_as_base64()
    Gets the screenshot of the current window as a base64 encoded string
    which is useful in embedded images in HTML.
Usage:  driver.get_screenshot_as_base64()

The likely bigger problem you'll face is that you're searching for an element and both of these methods are to save the whole screen. I'd suggest in addition to saving as base64 you read one of the many other questions on Stack about this subject if your intention was not to save the entire screen.

Johnny John Boy
  • 3,009
  • 5
  • 26
  • 50