HellAmbro / Trading212API

Unofficial Trading212 API
MIT License
59 stars 27 forks source link

Having error #28

Closed tachsin closed 1 year ago

tachsin commented 1 year ago

Running the example I get the following error:


[01:17:50] Authenticating                                                                                                                                    console.py:12
Traceback (most recent call last):
  File "C:\Users\tachs\Desktop\trading212\trading212_v2.py", line 9, in <module>
    equity = Equity(email='xxxxxx@gmail.com', password='xxxxxx',
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\pytrading212\trading212.py", line 239, in __init__
    super().__init__(email, password, driver, mode, constants.Trading.EQUITY)
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\pytrading212\trading212.py", line 50, in __init__
    self.driver.find_element(By.NAME, "email").send_keys(email)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 831, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="email"]"}
  (Session info: chrome=111.0.5563.147)
HellAmbro commented 1 year ago

Hi, this error is because the driver cannot find the "email" text field to enter the email. This is an error that happens infrequently, perhaps due to connection problems or errors in clicking the cookie button. You could try running the webdriverin full screen, or just restart the script.

Please be patient as the new version has just been released and there may be some errors that I could not detect. Thank you for the report and let me know.

tachsin commented 1 year ago

the problem persists, I tried maximizing the driver with driver.maximize_window(), no change

HellAmbro commented 1 year ago

Hi, thanks for reporting, can you please share your code, I've tried to reproduce the error but it's working for me

HellAmbro commented 1 year ago

This error can be related to internet connection and slow speed of T212 to load i think. Please follow these steps and let me know so i can update the core accordingly.

  1. clone this repository
  2. create a fresh and clean virtual environment
  3. add this line WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.NAME, "email"))) just below console.log("Authenticating") inside trading212.py You should have something like that
    
    console.log("Authenticating")
    WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.NAME, "email")))

Authenticate

self.driver.find_element(By.NAME, "email").send_keys(email) self.driver.find_element(By.NAME, "password").send_keys(password)



Please let me know, if you need more help you can also join inside Discord group or contact me by email or other ways.
I'm not able to reproduce the error since it never happens to me.