//Obtains Username and Password data for both banks private void obtainUserData() { readData.currentSheet = 1; readData.InitializeExcel(userDataPath); //readData.obtainExcelDataTest(); //Obtain NET Data NET_data NET_UserInfo = new NET_data(); readData.obtainDataNET(NET_UserInfo); NET_User = NET_UserInfo.User; NET_Pass = NET_UserInfo.Pass; //Obtain DCU Data DCU_data DCU_UserInfo = new DCU_data(); readData.obtainDataDCU(DCU_UserInfo); DCU_User = DCU_UserInfo.User; DCU_Pass = DCU_UserInfo.Pass; //Obtain Email Sender Data MailSender_data MailSender_UserInfo = new MailSender_data(); readData.obtainSendEmailData(MailSender_UserInfo); senderEmailAddress = MailSender_UserInfo.senderMailAddress; senderEmailPassword = MailSender_UserInfo.senderMailPassword; //Cleanup excel app readData.Cleanup(); }
public void obtainDataDCU(DCU_data UserInfo) { DCU_userDouble = Sheet.Cells[2, 3].value(); // *Note* Data is collected as a double and then converted to a string before being assigned to User variable. UserInfo.User = DCU_userDouble.ToString(); UserInfo.Pass = Sheet.Cells[3, 3].value(); }
public static void writeTransactionsToExcelDCU(DCU_data transactions) { try { lastRow += 1; MySheet.Cells[lastRow, 1] = transactions.Date; MySheet.Cells[lastRow, 2] = transactions.Description; MySheet.Cells[lastRow, 3] = transactions.Deposit; } catch (Exception) { } //MyBook.Close(); //MyApp.Quit(); }
public static void writeAccountsToExcelDCU(DCU_data accounts) { MySheet.Cells[3, 5] = accounts.Checking; MySheet.Cells[4, 5] = accounts.Savings; MySheet.Cells[6, 5] = "-" + accounts.Credit; }
//DCU Login private void DCUlogin() { //Open Chrome window ChromeOptions options = new ChromeOptions(); options.AddArgument("user-data-dir=C:/Users/RJ's Desktop/AppData/Local/Google/Chrome/User Data/Profile 1"); var cd = new ChromeDriver(options); //naviagte to DCU.org and login cd.Url = @"https://www.dcu.org/"; cd.Navigate(); IWebElement r = cd.FindElementById("userid"); r.SendKeys(DCU_User); r = cd.FindElementById("password"); r.SendKeys(DCU_Pass); r = cd.FindElementById("submitBtn"); r.Click(); //MessageBox.Show("derp wait"); cd.SwitchTo().Frame("appContainer"); //Get Data for Checking new WebDriverWait(cd, TimeSpan.FromSeconds(20)); new WebDriverWait(cd, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span")))); r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span")); lblDCUCheckingData.Text = r.GetAttribute("innerHTML"); //Get Data for Savings r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[2]/div[2]/div[1]/div[2]/span")); lblDCUSavingsData.Text = r.GetAttribute("innerHTML"); //Get Data for VISA Credit Card r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1023']/div/div[2]/div[1]/div[2]/span")); lblDCUCreditData.Text = r.GetAttribute("innerHTML"); //Change to account sheet for dcu WriteToExcel dcuExcel = new WriteToExcel(); currentSheet = 2; dcuExcel.ChangeSheet(currentSheet); //Store accounts data in DCU_data DCU_data accounts = new DCU_data() { Checking = lblDCUCheckingData.Text, Savings = lblDCUSavingsData.Text, Credit = lblDCUCreditData.Text }; WriteToExcel.writeAccountsToExcelDCU(accounts); //navigate to checking table r = cd.FindElement(By.XPath(".//*[@id='ext-gen43']/span")); r.Click(); //cd.SwitchTo().Frame("appContainer"); new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='lblAccountGrid']/span/h3")))); //obtain data IWebElement test = cd.FindElement(By.XPath(".//*[@id='lblAccountGrid']/span/h3")); System.Threading.Thread.Sleep(10000); //Check for number of rows to obtain data from for (int x = 1; x < 1000;) { // Store detected elements in a data list List <IWebElement> elementList = new List <IWebElement>(); elementList.AddRange(cd.FindElements(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[2]/div"))); if (elementList.Count > 0) { x++; lbltest.Text = x.ToString(); } else { break; } } //Convert element count to an integer. Decrease by 1 for accuracy when looping. int checkEleCount = Convert.ToInt32(lbltest.Text); checkEleCount--; //change to checking excel sheet currentSheet = 3; dcuExcel.ChangeSheet(currentSheet); //Add data for each transaction for (int x = 1; x <= checkEleCount;) { Label[] activeLabel = { lblDateRes, lblDesRes, lblDeposRes, lblWithRes, lblBalRes, }; // Default strings. Changes after assigned new value. string activeDate = "No good"; string activeDes = "No good"; string activeDepos = "No good"; string activeWith = "No good"; string activeBal = "No good"; string[] currentElement = { activeDate, activeDes, activeDepos, activeWith, activeBal }; //loop through each part of a row for each transaction for (int y = 2; y < 7;) { try { r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]/div")); activeLabel[y - 2].Text = r.GetAttribute("innerHTML"); currentElement[y - 2] = activeLabel[y - 2].Text; } catch (NoSuchElementException) { r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]")); activeLabel[y - 2].Text = r.GetAttribute("innerHTML"); currentElement[y - 2] = activeLabel[y - 2].Text; } //go to next column in the row y++; } DCU_data transactions = new DCU_data { Date = currentElement[0], Description = currentElement[1], Deposit = currentElement[2], Withdrawl = currentElement[3], Balance = currentElement[4], }; WriteToExcel.writeTransactionsToExcelDCU(transactions); //MessageBox.Show("Details were successfully added to the excel file!", "Success..", MessageBoxButtons.OK, MessageBoxIcon.Information); x++; } cd.Navigate().Back(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////Credit///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //MessageBox.Show("derp wait"); cd.SwitchTo().Frame("appContainer"); new WebDriverWait(cd, TimeSpan.FromSeconds(20)); new WebDriverWait(cd, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span")))); r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span")); //navigate to credit table r = cd.FindElement(By.XPath(".//*[@id='ext-gen55']/span")); r.Click(); //cd.SwitchTo().Frame("appContainer"); new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='lblAccountGrid']/span/h3")))); //obtain data IWebElement testCredit = cd.FindElement(By.XPath(".//*[@id='lblAccountGrid']/span/h3")); System.Threading.Thread.Sleep(10000); //Check for number of rows to obtain data from. This will rarely ever exceed 1000 per month. for (int x = 1; x < 1000;) { // Store detected elements in a data list List <IWebElement> elementList = new List <IWebElement>(); elementList.AddRange(cd.FindElements(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[2]/div"))); if (elementList.Count > 0) { x++; lbltest.Text = x.ToString(); } else { break; } } //Convert element count to an integer. Decrease by 1 for accuracy when looping int checkEleCountCredit = Convert.ToInt32(lbltest.Text); checkEleCountCredit--; //Change to credit dcu excel sheet WriteToExcel dcuExcelCredit = new WriteToExcel(); currentSheet = 4; dcuExcelCredit.ChangeSheet(currentSheet); //Add data for each transaction for (int x = 1; x <= checkEleCountCredit;) { Label[] activeLabel = { lblDateRes, lblDesRes, lblDeposRes, lblWithRes, lblBalRes, }; // Default strings. Changes after assigned new value string activeDate = "No good"; string activeDes = "No good"; string activeDepos = "No good"; string activeWith = "No good"; string activeBal = "No good"; string[] currentElement = { activeDate, activeDes, activeDepos, activeWith, activeBal }; //loop through each part of a row for each transaction for (int y = 2; y < 7;) { try { r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]/div")); activeLabel[y - 2].Text = r.GetAttribute("innerHTML"); currentElement[y - 2] = activeLabel[y - 2].Text; } catch (NoSuchElementException) { r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]")); activeLabel[y - 2].Text = r.GetAttribute("innerHTML"); currentElement[y - 2] = activeLabel[y - 2].Text; } y++; } DCU_data transactions = new DCU_data { Date = currentElement[0], Description = currentElement[1], Deposit = currentElement[2], Withdrawl = currentElement[3], Balance = currentElement[4], }; WriteToExcel.writeTransactionsToExcelDCU(transactions); x++; //for (int data = 0; data < 5;) //{ // if (activeData[data] == " ") // { // activeData[data] = ""; // } // data++; } ////set current date to be written as excel file name //FileName fileName = new FileName() //{ // currentDate = currentDate, // currentUser = currentUser, // excelPath = excelPath //}; //MyExcel.saveExcelFile(fileName); cd.Navigate().Back(); r = cd.FindElement(By.XPath(".//*[@id='logout']")); r.Click(); System.Threading.Thread.Sleep(10000); new WebDriverWait(cd, TimeSpan.FromSeconds(120)); new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='userid']")))); cd.Close(); System.Threading.Thread.Sleep(10000); cd.Quit(); }