Beispiel #1
0
    def test_from_webdriver(self):
        capabilities = webdriver.ChromeCapabilities()
        capabilities.add_argument('--headless')
        capabilities.add_argument('--no-sandbox')
        driver = webdriver.ChromeDriver(
            '/usr/local/bin/chromedriver',
            desired_capabilities=capabilities.desired)

        solutions = list()
        for i in range(5):
            driver.get('https://www.amazon.com/errors/validateCaptcha')

            captcha = AmazonCaptcha.from_webdriver(driver)
            solutions.append(len(captcha.solve()))

        driver.quit()

        self.assertIn(6, solutions)
Beispiel #2
0
 def get_captcha_help(self):
     try:
         log.info("Stuck on a captcha... Lets try to solve it.")
         captcha = AmazonCaptcha.from_webdriver(self.driver)
         solution = captcha.solve()
         log.info(f"The solution is: {solution}")
         if solution == "Not solved":
             self.driver.execute_script("window.location.reload()")
             time.sleep(5)
             self.get_captcha_help()
         else:
             self.driver.find_element_by_xpath(
                 '//*[@id="captchacharacters"]').send_keys(solution +
                                                           Keys.RETURN)
     except Exception as e:
         log.debug(e)
         log.info(
             "We were unable to solve the captcha, need help from the user."
         )
         self.notification_handler.send_notification(
             "Amazon bot is stuck on a captcha!")
Beispiel #3
0
 def get_captcha_help(self):
     if not self.on_captcha_page():
         log.info("Not on captcha page.")
         return
     try:
         log.info("Stuck on a captcha... Lets try to solve it.")
         captcha = AmazonCaptcha.from_webdriver(self.driver)
         solution = captcha.solve()
         log.info(f"The solution is: {solution}")
         if solution == "Not solved":
             log.info(f"Failed to solve, lets reload and get a new captcha.")
             self.driver.refresh()
             time.sleep(5)
             self.get_captcha_help()
         else:
             self.driver.find_element_by_xpath(
                 '//*[@id="captchacharacters"]'
             ).send_keys(solution + Keys.RETURN)
     except Exception as e:
         log.debug(e)
         log.info("Error trying to solve captcha. Refresh and retry.")
         self.driver.refresh()
         time.sleep(5)