// ePMP Radio Scraping Logic: public string Scrape_ePMP(ChromeDriver browser) { string RadioStats = null; var userId = browser.FindElementByName("username"); var pwd = browser.FindElementByName("password"); var login = browser.FindElementById("loginBtn"); userId.SendKeys("admin"); pwd.SendKeys("amatech1"); login.Click(); /****************************************************************************************** * Note for Error handling: * Max # of users: <span class="error-text">Maximum number of users reached.</span> * Wrong Username/Password: <span class="error-text">Wrong username or password</span> ******************************************************************************************/ //Have to set explicit waits for ePMP DOM to load...wireless connections be slow Thread.Sleep(500); try { var ePMPRssi = browser.FindElementById("dl_rssi").GetAttribute("title"); var ePMPSNR = browser.FindElementById("dl_snr").GetAttribute("title"); //var ePMP_EthernetStatus = browser.FindElementsById("alert-success").GetAttribute("title"); var ePMPUptime = browser.FindElementById("sys_uptime").GetAttribute("title"); var ePMP_DlMod = browser.FindElementById("dl_mcs_mode").GetAttribute("title"); var ePMP_ULMod = browser.FindElementById("ul_mcs_mode").GetAttribute("title"); RadioStats = $"{ePMPUptime.ToString()}\n"; RadioStats += $"{ePMPRssi.ToString()}\n"; RadioStats += $"{ePMPSNR.ToString()}\n"; RadioStats += $"{ePMP_DlMod.ToString()}\n"; RadioStats += $"{ePMP_ULMod.ToString()}\n"; } catch (NoSuchElementException NoElement) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"ePMP elements not found ref: {NoElement.ToString()}"); Console.ResetColor(); } catch (ElementNotVisibleException NoSee) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Cannot see elements on Webpage: {NoSee.ToString()}"); Console.ResetColor(); } // reboot req handling popup // ref stackoverflow: https://stackoverflow.com/questions/12744576/selenium-c-sharp-accept-confirm-box //string pageSrc = browser.PageSource; //find & click reboot button, currently not visible in DOM browser.FindElementByClassName("navbar-toggle").Click(); Thread.Sleep(500); browser.FindElementById("reboot_device").Click(); //Handle pop up asking us if we're sure we want to reboot, yes we are. BrowserHelper.HandleAlerts(browser); //Title's in ePMP radio are "preformated", will concantenate strings together and display. Console.WriteLine(RadioStats); Console.WriteLine("ePMP Complete..."); return(RadioStats); // return scrapedData; }
public string Spa122(ChromeDriver browser) { string ATAInfo = ""; try { browser.FindElementByName("user").SendKeys(userName); browser.FindElementByName("pwd").SendKeys(passWord); //login button? no unique ID for it so trying this way, hopefully I can count browser.FindElements(By.TagName("input"))[5].Click(); } catch (ElementNotVisibleException e) { Console.WriteLine($"Ran into error: {e.ToString()} \nAttempting refresh of page."); //sometimes page wouldn't load for spa122, will attempt a refresh, but this could go on endlessly soooo //nvm just re run old code vs callin whole method. browser.Navigate().Refresh(); browser.FindElementByName("user").SendKeys(userName); browser.FindElementByName("pwd").SendKeys(passWord); //login button? no unique ID for it so trying this way, hopefully I can count browser.FindElements(By.TagName("input"))[5].Click(); // throw; } catch (Exception e) { return(ATAInfo = $"Some error occured logging into ATA, ref: {e.ToString()}"); } try { //Go to network setup page. browser.FindElementById("trt_Network_Service.asp").Click(); var networkSettings = browser.FindElementById("d_4"); networkSettings.FindElement(By.TagName("a")).Click(); //Show DHCP reservations. browser.FindElementById("t3").Click(); //id's could be numbered like an array? need to find an spa122 with mulitples to test that, too bad they're becoming rare...or is it that bad? lolol var DHCP_Name = browser.FindElementByName("dhcp_select_name_0"); var DHCP_IP = browser.FindElementByName("dhcp_select_ip_0"); var DHCP_MAC = browser.FindElementByName("dhcp_select_mac_0"); ATAInfo += $"DCHP item: \nName:{DHCP_Name.Text}\nLAN IP: {DHCP_IP.Text}\nMAC: {DHCP_MAC.Text}"; } catch (NotFoundException NotHere) { Console.WriteLine($"Nothing found in DHCP Table {NotHere.ToString()}"); ATAInfo += "Nothing found in DCHP table\n"; //throw; } catch (Exception e) { return(ATAInfo = $"Couldn't get into ATA {e.ToString()}"); } //Considering there's only one ethernet port on the SPA122, will assume there's one item in DHCP, not always 100% //accurate as not every customer lets SPA122 run DHCP, but should be enough to go off of as far as equipment functionality //ATAInfo += $"Number of items found in DHCP: {DHCP_IP.Count.ToString()}"; //Console.WriteLine($"Number of items found in DHCP: {DHCP_IP.Count.ToString()}"); //for (int dhcp_list = 0; dhcp_list >= DHCP_IP.Count; dhcp_list++) //{ // ATAInfo += $"DHCP client name: {DHCP_Name[dhcp_list].Text} IP: {DHCP_IP[dhcp_list].Text} MAC: {DHCP_MAC[dhcp_list].Text}"; // Console.WriteLine($"DHCP client name: {DHCP_Name[dhcp_list].Text} IP: {DHCP_IP[dhcp_list].Text} MAC: {DHCP_MAC[dhcp_list].Text}"); //} try { //Check phones browser.FindElementById("trt_voice.asp").Click(); //this page is a mess, hope we really REALLY can count...you really don't wanna see this DOM man. but if you do uncomment this next line, ye be warned //Console.WriteLine(browser.PageSource.ToString()); //Data I want is stored in iframe will have to switch in and out of it. browser.SwitchTo().Frame(browser.FindElementById("iframe")); //Should be leading DIV containing ALL the info related to voice/uptime. var infoDiv = browser.FindElementById("Information"); var infoTable = infoDiv.FindElements(By.TagName("tr"))[8]; infoTable = infoTable.FindElements(By.TagName("td"))[3]; ATAInfo += $"ATA up time: {infoTable.FindElement(By.TagName("font")).Text}"; //Line 1: infoTable = infoDiv.FindElements(By.TagName("tr"))[16]; ATAInfo += $"Line 1 is {infoTable.FindElements(By.TagName("font"))[0].Text} hook and {infoTable.FindElements(By.TagName("font"))[1].Text} to SIP Server"; //line 2 infoTable = infoDiv.FindElements(By.TagName("tr"))[43]; //yeah that many rows in this table ATAInfo += $"Line 2 is {infoTable.FindElements(By.TagName("font"))[0].Text} hook and {infoTable.FindElements(By.TagName("font"))[1].Text} to SIP Server"; } catch (Exception NoIframe) { ATAInfo += $"Couldn't get voice info, no Iframe found or trouble switching to Iframe, ref: {NoIframe.ToString()}"; Console.WriteLine($"Couldn't get voice info, no Iframe found or trouble switching to Iframe, ref: {NoIframe.ToString()}"); throw; } Console.WriteLine("Going to reboot ATA..."); //Getting out of iframe, back into orginal DOM browser.SwitchTo().DefaultContent(); //move to reboot ATA browser.FindElementById("trt_Management.asp").Click(); var adminPage = browser.FindElementById("d_20"); //should be reboot button. adminPage.FindElement(By.TagName("a")).Click(); browser.FindElementById("t4").Click(); //handle JS alert try { BrowserHelper.HandleAlerts(browser); } catch (NoAlertPresentException BadAlert) { Console.WriteLine($"No alert found when attempting reboot, are lines in use? ref: {BadAlert.ToString()}"); ATAInfo += "No alert found when attempting reboot, are lines in use?"; // throw; } return(ATAInfo); }