Skip to content

Commit 2ec60ee

Browse files
committed
Fix auth
1 parent 9d34fb8 commit 2ec60ee

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### v0.2.8
2+
* fix auth
13
### v0.2.7
24
* fix candle stick
35
* adapt api with new T212 app

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pytrading212"
3-
version = "0.2.7"
3+
version = "0.2.8"
44
description = "Unofficial Trading212 API"
55
authors = ["HellAmbro <frambrosini1998@gmail.com>"]
66
license = "MIT License"

pytrading212/constants.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@
33

44
URL_LOGIN = "https://www.trading212.com/en/login"
55
CLASS_COOKIES_NOTICE_BUTTON = "CookiesNotice_button__q5YaL"
6-
CLASS_LOGIN_BUTTON = "SubmitButton_input__IV2dl"
6+
XPATH_LOGIN_BUTTON = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[4]/div/div'
77
CLASS_EQUITY_ICON = "equity-icon"
88
CLASS_CFD_ICON = "cfd-icon"
9-
PYTRADING212_VERSION = "0.2.6"
10-
SELECTOR_NEW_APP = ("#root > div > div > div > div > div > div > div:nth-child(1) > "
11-
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-105ug2t > "
12-
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-105ug2t > div > div > div > div "
13-
"> div > div > div > div.css-175oi2r.r-13awgt0 > div > "
14-
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div:nth-child(2) > div "
15-
"> div.css-175oi2r.r-13awgt0.r-1udh08x > div > div.css-175oi2r.r-13awgt0 > div > div > div > div "
16-
"> div > div > div.css-175oi2r.r-13awgt0 > div > "
17-
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div:nth-child(2) > div "
18-
"> div.css-175oi2r.r-13awgt0.r-1udh08x > div > div.css-175oi2r.r-13awgt0 > div > div > "
19-
"div.css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-1sncvnh > div > "
20-
"div.css-175oi2r.r-1loqt21.r-1otgn73 > div > div")
9+
PYTRADING212_VERSION = "0.2.8"
10+
XPATH_EMAIL = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[1]/div/div[1]/div[2]/input'
11+
XPATH_PASSWORD = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[2]/div/div/div[1]/div[2]/input'
2112
SELECTOR_MENU_BUTTON = ("#root > div > div > div > div > div > div > div:nth-child(1) > div > "
2213
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div > div > "
2314
"div:nth-child(1) > div > div > div:nth-child(2) > div > div:nth-child(5) > div > span > div")
@@ -57,6 +48,7 @@
5748

5849
ONE_WEEK = "ONE_WEEK"
5950

51+
6052
class Mode(Enum):
6153
"""Mode Type"""
6254
DEMO = "demo",

pytrading212/trading212.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,14 @@ def __init__(
4949

5050
console.log("Authenticating")
5151

52-
WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.NAME, "email")))
52+
WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.XPATH, constants.XPATH_EMAIL)))
5353

5454
# Authenticate
55-
self.driver.find_element(By.NAME, "email").send_keys(email)
56-
self.driver.find_element(By.NAME, "password").send_keys(password)
55+
self.driver.find_element(By.XPATH, constants.XPATH_EMAIL).send_keys(email)
56+
self.driver.find_element(By.XPATH, constants.XPATH_PASSWORD).send_keys(password)
5757

5858
# Click login button
59-
self.driver.find_element(By.CLASS_NAME, constants.CLASS_LOGIN_BUTTON).click()
60-
61-
# Close new app button, should be removed later
62-
try:
63-
WebDriverWait(self.driver, 30).until(expected_conditions.visibility_of_element_located(
64-
(By.CSS_SELECTOR, constants.SELECTOR_NEW_APP)))
65-
self.driver.find_element(By.CSS_SELECTOR, constants.SELECTOR_NEW_APP).click()
66-
except NoSuchElementException:
67-
pass
59+
self.driver.find_element(By.XPATH, constants.XPATH_LOGIN_BUTTON).click()
6860

6961
self.user_agent = self.driver.execute_script("return navigator.userAgent;")
7062

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pytrading212",
8-
version="0.2.7",
8+
version="0.2.8",
99
author="HellAmbro",
1010
author_email="frambrosini1998@gmail.com",
1111
description="Unofficial Trading212 API",

0 commit comments

Comments
 (0)