/// <summary> /// Clicks the user-specified element 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 element to click on</param> public void ClickAndWait(IWebElement buttonOrLinkElem) { // Error handler to make sure that the button that the tester passed in the parameter is actually on the page if (Browser.Exists(Bys.CBDLearnerPage.BackBtn)) { // This is a workaround to be able to use an IF statement on an IWebElement type. if (buttonOrLinkElem.GetAttribute("outerHTML") == BackBtn.GetAttribute("outerHTML")) { BackBtn.Click(); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.RCPPage.CBDTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == CBDTab.GetAttribute("outerHTML")) { buttonOrLinkElem.Click(); this.WaitUntil(TimeSpan.FromSeconds(180), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectBtn.GetAttribute("outerHTML")) { // NOTE: This sometimes does not work in Firefox whenever the tooltip for one of the tabs appears. Firefox // fails to click when a tooltip is covering the button. I changed this to a Javascript and it worked so far. // Monitor going forwards and if the javascript click also fails, we will have to implement a workaround // in the SwitchTabs method // buttonOrLinkElem.Click(); JavascriptUtils.Click(Browser, buttonOrLinkElem); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormContinueBtn); //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormContinueBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); this.WaitUntil(TimeSpan.FromSeconds(360), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormContinueBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML")) { AddReflectFormContinueBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormBrowseBtn, ElementCriteria.IsVisible); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormSubmitBtn.GetAttribute("outerHTML")) { AddReflectFormSubmitBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithReflectionsTabReady); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObservationBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObservationBtn.GetAttribute("outerHTML")) { RequestObservationBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.RequestObsFormObsNameTxt); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormObsNameTxt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormSearchBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); // Need to revisit the above 2 lines. For some reason, this needs a tiny static wait to work sometimes Thread.Sleep(0400); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormSearchBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormSearchBtn.GetAttribute("outerHTML")) { // 11/30/17: It failed today. Said "Failed to find any elements By.XPath: //tbody[@aria-label='Select Observer']". I looked on the // screenshot and the radio button never got returned, even though the label beneath it said "Showing 1-1 of 1". This tells me that // this is an application bug. Hopefully this fixes itself when DEV works on performance improvements. If not, and I see this again, // I might have to add some more logic below to keep clicking or something else // 11/05/17: For some reason, Selenium sometimes fails to click this button. So I am adding a Catch and using javascript based click // event if this fails // 1/25/18: Failed. The failure said that the Ok button (The button that is lcoated on the screen after clicking the Request button) // could not be found. Looked at screenshot, and it showed that the Search button did not get clicked (at least that is what I think, // because ALL observers showed inside the table), the Template (Part A) radio button DID get clicked, the Observer radio button // did NOT get clicked, so as a result, the Request button was disabled and could not be clicked. A video would really be helpful // to debug this, because I dont know why the observer table showed ALL observers (Did the search not get clicked even with the Try // Catch below? Did it actually get clicked, but the application failed to filter the observers (This would be an application bug)?) // Aside form those questions, the observer still showed in the table, but failed to get selected. I am adding a longer sleep here, // 5 milliseconds up from 3 milliseconds. Monitor going forward try { RequestObsFormSearchBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.RequestObsFormRdoBtnTbodyVisible, Criteria.CBDLearnerPage.RequestObsFormFirstRdoVisible); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); Thread.Sleep(0500); } catch { ((IJavaScriptExecutor)Browser).ExecuteScript("arguments[0].click()", RequestObsFormSearchBtn); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.RequestObsFormRdoBtnTbodyVisible, Criteria.CBDLearnerPage.RequestObsFormFirstRdoVisible); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); Thread.Sleep(0500); } return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormRequestBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormRequestBtn.GetAttribute("outerHTML")) { RequestObsFormRequestBtn.Click(); this.WaitForElement(Bys.CBDLearnerPage.RequestObsFormOkBtn, ElementCriteria.IsVisible); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormOkBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormOkBtn.GetAttribute("outerHTML")) { RequestObsFormOkBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormContinueBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML")) { AddReflectFormContinueBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ViewMoreRptsLnk)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ViewMoreRptsLnk.GetAttribute("outerHTML")) { ViewMoreRptsLnk.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.ReportsFormShowBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormShowBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormShowBtn.GetAttribute("outerHTML")) { ReportsFormShowBtn.Click(); Browser.WaitForElement(Bys.CBDLearnerPage.ReportsFormEPAObservCntChrt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled, ElementCriteria.HasText); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormCloseBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormCloseBtn.GetAttribute("outerHTML")) { ReportsFormCloseBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady); 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 element 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) { // Error handler to make sure that the button that the tester passed in the parameter is actually on the page if (Browser.Exists(Bys.CBDLearnerPage.BackBtn)) { // This is a workaround to be able to use an IF statement on an IWebElement type. if (buttonOrLinkElem.GetAttribute("outerHTML") == BackBtn.GetAttribute("outerHTML")) { BackBtn.Click(); this.WaitForInitialize(); return; } } if (Browser.Exists(Bys.RCPPage.CBDTab)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == CBDTab.GetAttribute("outerHTML")) { buttonOrLinkElem.Click(); this.WaitUntil(TimeSpan.FromSeconds(180), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectBtn.GetAttribute("outerHTML")) { // NOTE: This sometimes does not work in Firefox whenever the tooltip for one of the tabs appears. Firefox // fails to click when a tooltip is covering the button. However, this started working today. If it stops // working again, we will have to implement a workaround in the SwitchTabs method AddReflectBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormContinueBtn); //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormContinueBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); this.WaitUntil(TimeSpan.FromSeconds(360), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormContinueBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML")) { AddReflectFormContinueBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); //Browser.WaitForElement(Bys.CBDLearnerPage.AddReflectFormBrowseBtn, ElementCriteria.IsVisible); return; } } if (Browser.Exists(Bys.CBDLearnerPage.AddReflectFormSubmitBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormSubmitBtn.GetAttribute("outerHTML")) { AddReflectFormSubmitBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithReflectionsTabReady); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObservationBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObservationBtn.GetAttribute("outerHTML")) { RequestObservationBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.RequestObsFormObsNameTxt); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormObsNameTxt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); //Browser.WaitForElement(Bys.CBDLearnerPage.RequestObsFormSearchBtn, ElementCriteria.IsVisible, ElementCriteria.IsEnabled); // Need to revisit the above 2 lines. For some reason, this needs a tiny static wait to work sometimes //Thread.Sleep(0600); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormSearchBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormSearchBtn.GetAttribute("outerHTML")) { // 11/30/17: It failed today. Said "Failed to find any elements By.XPath: //tbody[@aria-label='Select Observer']" // I looked on the screenshot and the radio button never got returned, even though the label beneath it said // "Showing 1-1 of 1". This tells me that this is an application bug. Hopefully this fixes itself when DEV works // on performance improvements. If not, and I see this again, I might have to add some more logic below to keep // clicking or something else // 11/05/17: For some reason, selenium sometimes fails to click this button. So I am adding a Catch and using javascript based click event if this fails try { RequestObsFormSearchBtn.Click(); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.RequestObsFormRdoBtnTbodyVisible, Criteria.CBDLearnerPage.RequestObsFormFirstRdoVisible); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); // Adding a Sleep here for now until I have time to come back and add some dynamic wait criteria Thread.Sleep(0300); } catch { ((IJavaScriptExecutor)Browser).ExecuteScript("arguments[0].click()", RequestObsFormSearchBtn); this.WaitForElement(Bys.CBDLearnerPage.RequestObsFormRdoBtnTbody, TimeSpan.FromSeconds(60), ElementCriteria.IsVisible); this.WaitUntilAll(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); // Adding a Sleep here for now until I have time to come back and add some dynamic wait criteria Thread.Sleep(0300); } return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormRequestBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormRequestBtn.GetAttribute("outerHTML")) { RequestObsFormRequestBtn.Click(); this.WaitForElement(Bys.CBDLearnerPage.RequestObsFormOkBtn, ElementCriteria.IsVisible); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.RequestObsFormOkBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == RequestObsFormOkBtn.GetAttribute("outerHTML")) { RequestObsFormOkBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.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.CBDLearnerPage.AddReflectFormContinueBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == AddReflectFormContinueBtn.GetAttribute("outerHTML")) { AddReflectFormContinueBtn.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.AddReflectFormBrowseBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ViewMoreRptsLnk)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ViewMoreRptsLnk.GetAttribute("outerHTML")) { ViewMoreRptsLnk.Click(); WaitUtils.WaitForPopup(Browser, TimeSpan.FromSeconds(30), Bys.CBDLearnerPage.ReportsFormShowBtn); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.LoadElementDoneLoading); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormShowBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormShowBtn.GetAttribute("outerHTML")) { ReportsFormShowBtn.Click(); Browser.WaitForElement(Bys.CBDLearnerPage.ReportsFormEPAObservCntChrt, ElementCriteria.IsVisible, ElementCriteria.IsEnabled, ElementCriteria.HasText); return; } } if (Browser.Exists(Bys.CBDLearnerPage.ReportsFormCloseBtn)) { if (buttonOrLinkElem.GetAttribute("outerHTML") == ReportsFormCloseBtn.GetAttribute("outerHTML")) { ReportsFormCloseBtn.Click(); this.WaitUntil(TimeSpan.FromSeconds(120), Criteria.CBDLearnerPage.PageReadyWithProgramLearningTabReady); 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."); } }