@@ -38,10 +38,8 @@ def log_in(self):
3838 time .sleep (1 )
3939 self ._click_i_look_good ()
4040
41- if self ._browser .find_by_xpath (LOGIN_SIGN_IN_BUTTON_XPATH ):
42- self ._browser .click_by_xpath (LOGIN_SIGN_IN_BUTTON_XPATH )
43- self ._browser .wait_until_visible (
44- By .XPATH , '//*[@id="uhfLogo" or @id="microsoft"]' , 10 )
41+ self ._browser .click_element (By .XPATH , LOGIN_SIGN_IN_BUTTON_XPATH , ignore_no_ele_exc = True )
42+ self ._browser .wait_until_visible (By .XPATH , '//*[@id="uhfLogo" or @id="microsoft"]' , 10 )
4543
4644 self ._log_into_bing_mobile () if self ._browser .mobile_mode else self ._log_into_bing_pc ()
4745 time .sleep (1 )
@@ -61,21 +59,21 @@ def _enter_password(self):
6159
6260 def _enter_otc (self ):
6361 logging .debug (msg = 'OTC information is provided.' )
64- if not self ._browser .find_elements_by_name ( LOGIN_OTC_INPUT_NAME ):
62+ if not self ._browser .find_elements ( By . NAME , LOGIN_OTC_INPUT_NAME ):
6563 self ._switch_to_otc_method ()
6664 totp = pyotp .TOTP (self .otp_secret )
6765 otc = totp .now ()
6866 self ._enter_login_screen_value (LOGIN_OTC_INPUT_NAME , otc , 'Sent OTC' )
6967
7068 def _switch_to_otc_method (self ):
7169 logging .debug (msg = 'Switching to OTC verification method.' )
72- sign_in_another_way = self ._browser .find_by_id ( 'signInAnotherWay' )
70+ sign_in_another_way = self ._browser .find_elements ( By . ID , 'signInAnotherWay' )
7371 if not sign_in_another_way :
7472 raise FailToSignInException ('Sign in is failed. Unable to switch to OTC verification method. Did not find the "sign in another way" link.' )
7573
7674 sign_in_another_way [0 ].click ()
7775 time .sleep (1 )
78- verificaiton_methods = self ._browser .find_by_xpath ( '//div[@data-bind="text: display"]' )
76+ verificaiton_methods = self ._browser .find_elements ( By . XPATH , '//div[@data-bind="text: display"]' )
7977 for vm in verificaiton_methods :
8078 if 'mobile app' in vm .text :
8179 vm .click ()
@@ -84,60 +82,43 @@ def _switch_to_otc_method(self):
8482 raise FailToSignInException (f'Sign in is failed. Unable to switch to OTC verification method. No such option. All options are:\n { [x .text for x in verificaiton_methods ]} ' )
8583
8684 def _enter_login_screen_value (self , ele_name , value , msg ):
87- self ._browser .wait_until_clickable (By .NAME , ele_name , 10 )
88- self ._browser .send_key_by_name ( ele_name , value )
85+ self ._browser .wait_until_visible (By .NAME , ele_name , 10 )
86+ self ._browser .send_key ( By . NAME , ele_name , value )
8987 logging .debug (msg = msg )
9088 time .sleep (0.5 )
91- self ._browser .send_key_by_name ( ele_name , Keys .RETURN )
89+ self ._browser .send_key ( By . NAME , ele_name , Keys .RETURN )
9290 time .sleep (0.5 )
9391
9492 def sign_in_prompt (self ):
9593 time .sleep (3 )
96- sign_in_prompt_msg = self ._browser .find_by_class ( 'simpleSignIn' )
94+ sign_in_prompt_msg = self ._browser .find_elements ( By . CLASS_NAME , 'simpleSignIn' )
9795 if sign_in_prompt_msg :
9896 logging .debug (msg = 'Detected sign-in prompt' )
99- self ._browser .wait_until_clickable (By .LINK_TEXT , 'Sign in' , 15 )
100- self ._browser .find_element_by_link_text ( 'Sign in' ). click ( )
97+ self ._browser .wait_until_visible (By .LINK_TEXT , 'Sign in' , 15 )
98+ self ._browser .click_element ( By . LINK_TEXT , 'Sign in' )
10199 logging .info (msg = 'Clicked sign-in prompt' )
102100 time .sleep (4 )
103101
104102 def _log_into_bing_pc (self ):
105103 self ._browser .get (BING_SEARCH_URL )
106104 self ._browser .wait_until_clickable (By .ID , 'id_l' , 5 )
107- self ._browser .click_by_id ( 'id_l' )
105+ self ._browser .click_element ( By . ID , 'id_l' )
108106 time .sleep (0.1 )
109107 self ._browser .wait_until_clickable (By .ID , 'id_l' , 5 )
110- # self._browser.wait_until_clickable(
111- # By.XPATH, "//*[text()='Sign in' and @aria-hidden='false']//parent::a", 5)
112- # if self._browser.find_by_xpath("//*[text()='Sign in' and @aria-hidden='false']//parent::a"):
113- # self._browser.click_by_xpath(
114- # "//*[text()='Sign in' and @aria-hidden='false']//parent::a")
115- # self._browser.wait_until_clickable(
116- # By.XPATH, "//*[text()='Sign in']//parent::a", 5)
117108
118109 def _log_into_bing_mobile (self ):
119110 self ._browser .get (BING_SEARCH_URL )
120- self ._browser .wait_until_clickable (
121- By .XPATH , '//*[@aria-label="Preferences"]' , 5 )
122- self ._browser .click_by_xpath ('//*[@aria-label="Preferences"]' )
111+ self ._browser .wait_until_clickable (By .XPATH , '//*[@aria-label="Preferences"]' , 10 )
112+ self ._browser .click_element (By .XPATH , '//*[@aria-label="Preferences"]' )
123113 time .sleep (0.1 )
124- self ._browser .wait_until_clickable (
125- By .XPATH , "//*[text()='Sign in']//parent::a" , 5 )
126- if self ._browser .find_by_xpath ("//*[text()='Sign in']//parent::a" ):
127- self ._browser .click_by_xpath ("//*[text()='Sign in']//parent::a" )
128- self ._browser .wait_until_clickable (
129- By .XPATH , '//*[@aria-label="Preferences"]' , 5 )
114+ self ._browser .wait_until_clickable (By .XPATH , "//*[text()='Sign in']//parent::a" , 5 )
115+ if self ._browser .click_element (By .XPATH , "//*[text()='Sign in']//parent::a" , ignore_no_ele_exc = True ):
116+ self ._browser .wait_until_clickable (By .XPATH , '//*[@aria-label="Preferences"]' , 5 )
130117 else :
131- self ._browser .click_by_xpath ( '//*[@aria-label="Preferences"]' )
118+ self ._browser .click_element ( By . XPATH , '//*[@aria-label="Preferences"]' )
132119
133120 def _accept_bnp (self ):
134- btn = self ._browser .find_elements_by_class_name ('bnp_btn_accept' )
135- if not btn :
136- return
137- btn [0 ].click ()
121+ self ._browser .click_element (By .CLASS_NAME , 'bnp_btn_accept' , ignore_no_ele_exc = True )
138122
139123 def _click_i_look_good (self ):
140- btn = self ._browser .find_elements_by_id ('iLooksGood' )
141- if not btn :
142- return
143- btn [0 ].click ()
124+ self ._browser .click_element (By .ID , 'iLooksGood' , ignore_no_ele_exc = True )
0 commit comments