if($visitFound eq 0){ $oa_mech->get($addv_url); die unless ($oa_mech->success); sleep(2); #get patient ID $oa_mech->click({id => 'ctl00_phFolderContent_Button1', synchronize => 0}); for (1..10){ last if $oa_mech->is_visible( xpath => '//*[@id="ctl04_popupBase_btnSearch"]'); sleep(1); } $oa_form_name = "form1"; $oa_mech->form_name($oa_form_name); $oa_mech->set_fields( '#ctl04_popupBase_txtSearch' => 'Hester', '#ctl04_popupBase_DOB_Month' => $birthMonth, '#ctl04_popupBase_DOB_Day' => $birthDay, '#ctl04_popupBase_DOB_Year' => $birthYear, ); $oa_mech->click({id => 'ctl04_popupBase_btnSearch', synchronize => 0}); for (1..10){ #wait for visit page to reload last if $oa_mech->is_visible( xpath => '//*[@id="ctl00_phFolderContent_DateVisited_Year"]'); sleep(1); } }