/// <summary> /// Clicks the user-specified button, link, tab, etc. and then waits for a window to close or open, or a page to load, /// depending on the element that was clicked /// </summary> /// <param name="buttonOrLinkElem">The button element</param> public void ClickAndWait(IWebElement buttonOrLinkElem) { if (Browser.Exists(Bys.CBDProgDeanPage.LearnersTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == LearnersTab.GetAttribute("outerHTML")) { LearnersTab.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LearnersTblBodyRowVisibleAndEnabled); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.RCPPage.CBDTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == Browser.FindElement(Bys.RCPPage.CBDTab).GetAttribute("outerHTML")) { buttonOrLinkElem.Click(); this.WaitUntil(TimeSpan.FromSeconds(180), Criteria.CBDProgDeanPage.PageReady); return; } } if (Browser.Exists(Bys.CBDProgDeanPage.AddRemoveFlagFormRemoveFlagBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddRemoveFlagFormRemoveFlagBtn.GetAttribute("outerHTML")) { AddRemoveFlagFormRemoveFlagBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LearnersTblBodyRowVisibleAndEnabled); this.WaitUntil(Criteria.CBDProgDeanPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDProgDeanPage.AddRemoveFlagFormSaveFlagBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddRemoveFlagFormSaveFlagBtn.GetAttribute("outerHTML")) { AddRemoveFlagFormSaveFlagBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LearnersTblBodyRowVisibleAndEnabled); this.WaitUntil(Criteria.CBDProgDeanPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDProgDeanPage.AddNotesFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddNotesFormSubmitBtn.GetAttribute("outerHTML")) { AddNotesFormSubmitBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LearnersTblBodyRowVisibleAndEnabled); this.WaitUntil(Criteria.CBDProgDeanPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.RCPPage.LogoutLnk)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == LogoutLnk.GetAttribute("outerHTML")) { ElemSet.ScrollToElement(Browser, LogoutLnk); LogoutLnk.Click(); new WebDriverWait(Browser, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.UrlContains("login")); return; } } if (Browser.Exists(Bys.CBDProgDeanPage.AddSupportingDocumentationFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddSupportingDocumentationFormSubmitBtn.GetAttribute("outerHTML")) { AddSupportingDocumentationFormSubmitBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LearnersTblBodyRowVisibleAndEnabled); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDProgDeanPage.LoadElementDoneLoading); return; } } else { throw new Exception("No button or link was found with your passed parameter. You either need to add this button to a new If statement, " + "or if the button is already added, then the page you were on did not contain the button."); } }
/// <summary> /// Clicks the user-specified button, link, tab, etc. and then waits for a window to close or open, or a page to load, /// depending on the element that was clicked /// </summary> /// <param name="buttonOrLinkElem">The button element</param> public void ClickAndWait(IWebElement buttonOrLinkElem) { if (Browser.Exists(Bys.CBDProgDirectorPage.AddRemoveFlagFormRemoveFlagBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddRemoveFlagFormRemoveFlagBtn.GetAttribute("outerHTML")) { AddRemoveFlagFormRemoveFlagBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LearnersTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.RCPPage.CBDTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == Browser.FindElement(Bys.RCPPage.CBDTab).GetAttribute("outerHTML")) { buttonOrLinkElem.Click(); this.WaitUntil(TimeSpan.FromSeconds(180), Criteria.CBDProgDirectorPage.PageReady); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AddRemoveFlagFormSaveFlagBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddRemoveFlagFormSaveFlagBtn.GetAttribute("outerHTML")) { AddRemoveFlagFormSaveFlagBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LearnersTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.SchedProgMeetFormScheduleBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == SchedProgMeetFormScheduleBtn.GetAttribute("outerHTML")) { SchedProgMeetFormScheduleBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LearnersTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AddNotesFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddNotesFormSubmitBtn.GetAttribute("outerHTML")) { AddNotesFormSubmitBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LearnersTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AssignObsFormNextBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AssignObsFormNextBtn.GetAttribute("outerHTML")) { AssignObsFormNextBtn.Click(); Browser.WaitForElement(Bys.CBDProgDirectorPage.AssignObsFormBackBtn, ElementCriteria.IsEnabled); Browser.WaitForElement(Bys.CBDProgDirectorPage.AssignObsFormBackBtn, ElementCriteria.IsVisible); Browser.WaitForElement(Bys.CBDProgDirectorPage.AssignObsFormBackBtn, ElementCriteria.HasText); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AssignObsFormSearchBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AssignObsFormSearchBtn.GetAttribute("outerHTML")) { AssignObsFormSearchBtn.Click(); Browser.WaitForElement(Bys.CBDProgDirectorPage.AssignObsFormObserverNameTxt, ElementCriteria.IsEnabled); this.WaitForInitialize(); Thread.Sleep(1000); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AssignObsFormAssignBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AssignObsFormAssignBtn.GetAttribute("outerHTML")) { AssignObsFormAssignBtn.Click(); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.CompCommiteeTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == CompCommiteeTab.GetAttribute("outerHTML")) { CompCommiteeTab.Click(); // Note that the if this is a new environment, then this will fail because the Agenda table will not have any rows. You have to log in manually and create // an agenda so that the agenda table gets rows this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.AgendaTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.CreateNewAgendaLnk)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == CreateNewAgendaLnk.GetAttribute("outerHTML")) { CreateNewAgendaLnk.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDProgDirectorPage.CreateNewAgendaFormProgramSelElemHasItemsAndIsEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.CreateNewAgendaFormCreateBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == CreateNewAgendaFormCreateBtn.GetAttribute("outerHTML")) { CreateNewAgendaFormCreateBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); // This failed once and the screenshot showed that the load element was still there. So the above wait criteria didnt work, // maybe there is a second load icon that appears. So lets condition this so that if the form did not close yet, then wait // again for the load icon to disappear. if (Browser.FindElements(Bys.CBDProgDirectorPage.CreateNewAgendaFormCreateBtn).Count > 0) { this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); } return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.SetStatusFormConfirmBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == SetStatusFormConfirmBtn.GetAttribute("outerHTML")) { SetStatusFormConfirmBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.FinalizeAgendaBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == FinalizeAgendaBtn.GetAttribute("outerHTML")) { FinalizeAgendaBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.FinalizeAgendaFormFinalizeBtnIsEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.FinalizeAgendaFormFinalizeBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == FinalizeAgendaFormFinalizeBtn.GetAttribute("outerHTML")) { FinalizeAgendaFormFinalizeBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(60), Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared, Criteria.CBDProgDirectorPage.AgendaTblRowBodyVisibleAndEnabled); return; } } if (Browser.Exists(Bys.RCPPage.LogoutLnk)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == LogoutLnk.GetAttribute("outerHTML")) { ElemSet.ScrollToElement(Browser, LogoutLnk); LogoutLnk.Click(); new WebDriverWait(Browser, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.UrlContains("login")); return; } } if (Browser.Exists(Bys.CBDProgDirectorPage.AddSupportingDocumentationFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddSupportingDocumentationFormSubmitBtn.GetAttribute("outerHTML")) { AddSupportingDocumentationFormSubmitBtn.Click(); this.WaitUntilAll(Criteria.CBDProgDirectorPage.LearnersTblRowBodyVisibleAndEnabled, Criteria.CBDProgDirectorPage.LoadElementClassAttributeSetToHide, Criteria.CBDProgDirectorPage.LoadElementDisappeared); return; } } else { throw new Exception("No button or link was found with your passed parameter. You either need to add this button to a new If statement, " + "or if the button is already added, then the page you were on did not contain the button."); } }