@@ -184,13 +184,45 @@ public function goto_widget_selection() {
184184
185185 // driver currently on tawk-iframe frame
186186 // incase the current session hasn't logged in to the plugin yet.
187- $ login_form_id = '#loginForm ' ;
188- $ login_form = $ this ->driver ->find_and_check_element ( $ login_form_id );
189- if ( false === is_null ( $ login_form ) ) {
190- $ this ->driver ->find_element_and_input ( '#email ' , $ this ->tawk ->username );
191- $ this ->driver ->find_element_and_input ( '#password ' , $ this ->tawk ->password );
192- $ this ->driver ->find_element_and_click ( '#login-button ' );
187+ $ login_button_id = '#login-button ' ;
188+ $ login_button = $ this ->driver ->find_and_check_element ( $ login_button_id );
189+ if ( true === is_null ( $ login_button ) ) {
190+ return ;
191+ }
192+
193+ $ this ->driver ->find_element_and_click ( '#login-button ' );
194+
195+ $ window_handles = $ this ->driver ->get_driver ()->getWindowHandles ();
196+ $ this ->driver ->get_driver ()->switchTo ()->window ( end ( $ window_handles ) );
197+
198+ // driver currently on tawk.to OAuth login popout.
199+
200+ // handle currently logged in page.
201+ $ allow_id = '#allow ' ;
202+ $ allow_button = $ this ->driver ->find_and_check_element ( $ allow_id );
203+ if ( false === is_null ( $ allow_button ) ) {
204+ $ allow_button ->click ();
205+ $ this ->driver ->get_driver ()->switchTo ()->window ( reset ( $ window_handles ) );
206+ $ this ->driver ->wait_for_frame_and_switch ( '#tawk-iframe ' , 10 );
207+ return ;
193208 }
209+
210+ // handle login page.
211+ $ this ->driver ->find_element_and_input ( '#email ' , $ this ->tawk ->username );
212+ $ this ->driver ->find_element_and_input ( '#password ' , $ this ->tawk ->password );
213+ $ this ->driver ->find_element_and_click ( 'button[type="submit"] ' );
214+
215+ // handle consent page.
216+ $ allow_id = '#allow ' ;
217+ $ allow_button = $ this ->driver ->find_and_check_element ( $ allow_id );
218+
219+ if ( false === is_null ( $ allow_button ) ) {
220+ $ allow_button ->click ();
221+ }
222+
223+ // go back to tawk-iframe frame.
224+ $ this ->driver ->get_driver ()->switchTo ()->window ( reset ( $ window_handles ) );
225+ $ this ->driver ->wait_for_frame_and_switch ( '#tawk-iframe ' , 10 );
194226 }
195227
196228 public function goto_visibility_options () {
0 commit comments