@@ -58,21 +58,18 @@ def __init__(
5858 # Click login button
5959 self .driver .find_element (By .CLASS_NAME , constants .CLASS_LOGIN_BUTTON ).click ()
6060
61- # Wait until the site is fully loaded, 120 seconds is a lot, but the site sometimes is very slow
62- WebDriverWait (self .driver , 120 ).until (expected_conditions .
63- visibility_of_element_located ((By .CLASS_NAME , "company-logo" )))
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
6468
6569 self .user_agent = self .driver .execute_script ("return navigator.userAgent;" )
6670
67- # Redirect to correct mode, DEMO or LIVE
68- if mode .name not in self .driver .current_url :
69- self .driver .get (self .base_url )
70- WebDriverWait (self .driver , 120 ).until (expected_conditions .
71- visibility_of_element_located ((By .CLASS_NAME , "company-logo" )))
72-
73- # Switch to right trading session: CFD or EQUITY
74- self .switch_to (trading = trading )
75-
71+ # Switch to get also DEMO token
72+ self .switch ()
7673 # Get session cookie
7774 cookies = self .driver .get_cookies ()
7875 if cookies is not None :
@@ -103,22 +100,19 @@ def finish(self):
103100 console .log ("Closing session." )
104101 self .driver .close ()
105102
106- def switch_to (self , trading : constants .Trading ):
107- if not self .driver .find_elements (By .ID , "platform-loader" ):
108- self .driver .find_element (By .CLASS_NAME , "account-menu-info" ).click ()
109- WebDriverWait (self .driver , 10 ).until (expected_conditions .
110- visibility_of_element_located ((By .CLASS_NAME , "account-types" )))
111- element_account_types = self .driver .find_element (By .CLASS_NAME , "account-types" )
112- if trading == constants .Trading .CFD :
113- element_account_types .find_element (By .CLASS_NAME , "cfd" ).click ()
114- WebDriverWait (self .driver , 60 ).until (expected_conditions .
115- visibility_of_element_located ((By .CLASS_NAME , "cfd-icon" )))
116- elif trading == constants .Trading .EQUITY :
117- element_account_types .find_element (By .CLASS_NAME , "equity" ).click ()
118- WebDriverWait (self .driver , 60 ).until (expected_conditions .
119- visibility_of_element_located ((By .CLASS_NAME , "equity-icon" )))
120- else :
121- self .switch_to (trading )
103+ def switch (self ):
104+ WebDriverWait (self .driver , 30 ).until (expected_conditions .visibility_of_element_located (
105+ (By .CSS_SELECTOR , constants .SELECTOR_MENU_BUTTON )))
106+ self .driver .find_element (By .CSS_SELECTOR , constants .SELECTOR_MENU_BUTTON ).click ()
107+
108+ self .driver .execute_script ("arguments[0].scroll(0, arguments[0].scrollHeight);" ,
109+ self .driver .find_element (By .CSS_SELECTOR , constants .SELECTOR_MENU_LIST ))
110+ self .driver .find_element (By .CSS_SELECTOR , constants .SELECTOR_SWITCH_DEMO ).click ()
111+ WebDriverWait (self .driver , 30 ).until (expected_conditions .visibility_of_element_located (
112+ (By .CSS_SELECTOR , constants .SELECTOR_DEMO_EQUITY )))
113+ self .driver .find_element (By .CSS_SELECTOR , constants .SELECTOR_DEMO_EQUITY ).click ()
114+ # Wait some seconds to initialize cookies
115+ time .sleep (5 )
122116
123117 def get_funds (self ):
124118 """Get your funds, free, available."""
0 commit comments