Esempio n. 1
0
 protected void Type(string path, string pathType, string value)
 {
     if (pathType == "id")
     {
         IWebElement element = driver.FindElementById(path);
         element.SendKeys(value);
         TestCase.Log("Entered " + value + " at element with id=" + path);
     }
     if (pathType == "name")
     {
         IWebElement element = driver.FindElementByName(path);
         element.SendKeys(value);
         TestCase.Log("Entered " + value + " at element with name=" + path);
     }
     if (pathType == "class")
     {
         IWebElement element = driver.FindElementByClassName(path);
         element.SendKeys(value);
         TestCase.Log("Entered " + value + " at element with class=" + path);
     }
     if (pathType == "xpath")
     {
         IWebElement element = driver.FindElementByXPath(path);
         element.SendKeys(value);
         TestCase.Log("Entered " + value + " at element with xpath=" + path);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Método responsável por realizar o login no linkedin
        /// </summary>
        /// <returns>PhantomJSDriver logado</returns>
        private static PhantomJSDriver RealizaLogin()
        {
            var options = new PhantomJSOptions();

            options.AddAdditionalCapability("permissions.default.stylesheet", 2);
            options.AddAdditionalCapability("permissions.default.image", 2);
            options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/35.0");

            var loPhantom = new PhantomJSDriver(options);
            var time      = 20;

            loPhantom.Manage().Window.Size = new Size(2000, 2000);
            loPhantom.Navigate().GoToUrl("https://www.linkedin.com/uas/login?goback=&trk=hb_signin");

            var loginForm = loPhantom.FindElementByName("session_key");
            var passForm  = loPhantom.FindElementByName("session_password");
            var loButton  = loPhantom.FindElementByName("signin");

            loginForm.Clear();
            passForm.Clear();
            loginForm.SendKeys(""); //Login
            passForm.SendKeys("");  //Senha

            loButton.Click();

            var wait = new WebDriverWait(loPhantom, TimeSpan.FromSeconds(time));

            wait.Until(drv => drv.Url.Contains("feed"));

            return(loPhantom);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            using (var driver = new PhantomJSDriver())
            {
                driver.Navigate().GoToUrl("http://www.google.com/");

                var query = driver.FindElementByName("q");
                query.SendKeys("hello");
                query.Submit();

                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                wait.Until(d => d.Title.ToLower().StartsWith("hello"));

                Console.WriteLine("Page title: " + driver.Title);

                var resultsPanel  = driver.FindElementById("search");
                var searchResults = resultsPanel.FindElements(By.XPath(".//a"));

                foreach (var result in searchResults)
                {
                    Console.WriteLine(result.Text);
                }
            }

            Console.ReadKey();
        }
Esempio n. 4
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            try
            {
                switch (Parameters[0])
                {
                case "id":
                    element = driver.FindElementById(Parameters[1]);
                    break;

                case "name":
                    element = driver.FindElementByName(Parameters[1]);
                    break;

                case "class":
                    element = driver.FindElementByClassName(Parameters[1]);
                    break;

                case "text":
                    element = driver.FindElementByLinkText(Parameters[1]);
                    break;
                }
            }
            catch (Exception e)
            {
                //Element was not found
                return(false);
            }

            //Wrong parameters were used
            return(element != null);
        }
Esempio n. 5
0
        public AccountDetail GetAccountDetails()
        {
            if (driver != null)
            {
                string   abc  = string.Empty;
                Document body = null;
                ReadOnlyCollection <IWebElement> alltables;
                try
                {
                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_menu");
                    driver.FindElementById("RRADTlink").Click();

                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_txn");

                    SelectElement elem = new SelectElement(driver.FindElementById("fldacctnodesc"));
                    elem.SelectByValue(this.Value);

                    driver.FindElementByName("fldsubmit").Click();

                    alltables = driver.FindElementsByClassName("infotable");
                    abc       = alltables[0].GetAttribute("innerHTML");
                    body      = Supremes.Dcsoup.Parse(abc);
                }
                catch
                {
                    throw new Exception("(ErrorCode:6) Service Or Network not Available Or Might be Some Rendering Problem Try again.");
                }

                AccountDetail detail = new AccountDetail(this.Value, driver);
                detail.AccountTitle  = body.Body.TextNodes[1].Text;
                detail.AccountNumber = body.Body.TextNodes[4].Text;

                abc  = alltables[2].GetAttribute("innerHTML");
                body = Supremes.Dcsoup.Parse(abc);

                detail.CurrentBalance   = Convert.ToDouble(body.Body.TextNodes[2].Text.Replace(",", ""));
                detail.AmountOnHold     = Convert.ToDouble(body.Body.TextNodes[4].Text.Replace(",", ""));
                detail.UnClearedFunds   = Convert.ToDouble(body.Body.TextNodes[6].Text.Replace(",", ""));
                detail.OverDraftLimit   = Convert.ToDouble(body.Body.TextNodes[8].Text.Replace(",", ""));
                detail.AvailableBalance = Convert.ToDouble(body.Body.TextNodes[10].Text.Replace(",", ""));
                detail.NetAvailableBalanceForWithDrawls = Convert.ToDouble(body.Body.TextNodes[12].Text.Replace(",", ""));

                return(detail);
            }
            else
            {
                throw new Exception("(ErrorCode:5) Account object not initialized");
            }
        }
Esempio n. 6
0
 private void login()
 {
     try
     {
         var username = driver.FindElementById("login-username");
         var password = driver.FindElementById("login-password");
         username.SendKeys("oddsbetting");
         password.SendKeys("oddsbettings");
         var button = driver.FindElementByName("login-submit");
         button.Click();
     }
     catch (Exception e)
     {
         return;
     }
 }
Esempio n. 7
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            switch (Parameters[0])
            {
            case "id":
                element = driver.FindElementById(Parameters[1]);
                break;

            case "class":
                element = driver.FindElementByClassName(Parameters[1]);
                break;

            case "tag":
                element = driver.FindElementByTagName(Parameters[1]);
                break;

            case "text":
                element = driver.FindElementByLinkText(Parameters[1]);
                break;

            case "name":
                element = driver.FindElementByName(Parameters[1]);
                break;

            default:
                return(false);
            }

            //Element not found
            if (element == null)
            {
                return(false);
            }
            try
            {
                element.Click();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
                //Element not clickable
            }
        }
Esempio n. 8
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            try
            {
                switch (Parameters[0])
                {
                case "id":
                    element = driver.FindElementById(Parameters[1]);
                    break;

                case "class":
                    element = driver.FindElementByClassName(Parameters[1]);
                    break;

                case "name":
                    element = driver.FindElementByName(Parameters[1]);
                    break;
                }
            }
            catch (Exception e)
            {
                //Element was not found
                return(false);
            }

            //Wrong parameters used
            if (element == null)
            {
                return(false);
            }
            try
            {
                element.SendKeys(Parameters[2]);
                return(true);
            }
            catch (Exception e)
            {
                //ERROR element not editable/interactable
                return(false);
            }
        }
Esempio n. 9
0
        public HblBank(string Username, string Password)
        {
            try
            {
                driver.Navigate().GoToUrl("https://hblibank.com.pk/");
            }
            catch
            {
                throw new Exception("(ErrorCode:1) Bank Service Unavailable Or Network Not Available");
            }

            try
            {
                driver.FindElementById("btnProceed").Click();
                driver.FindElementByName("fldLoginUserId").SendKeys(Username);
                driver.FindElementByName("fldPassword").SendKeys(Password);
                driver.FindElementById("foo").Click();


                ReadOnlyCollection <String> handles = driver.WindowHandles;
                driver.SwitchTo().Window(handles[0]);
            }
            catch
            {
                throw new Exception("(ErrorCode:2) Service Response Delay");
            }
            try
            {
                driver.SwitchTo().Frame("frame_menu");
                driver.FindElementById("RRAAClink").Click();
            }
            catch
            {
                throw new Exception("(ErrorCode:3) Credentials are not Valid Or Network Not Available");
            }


            try
            {
                driver.SwitchTo().Window(driver.CurrentWindowHandle);
                driver.SwitchTo().Frame("frame_txn");
                string abc = driver.FindElementByName("fldacctno").GetAttribute("innerHTML");

                Document body    = Supremes.Dcsoup.Parse(abc);
                Elements options = body.Select("option");

                Accounts = new List <Account>();

                foreach (Element el in options)
                {
                    if (!el.Val.Equals(""))
                    {
                        Accounts.Add(new Account(driver)
                        {
                            Name = el.OwnText, Value = el.Val
                        });
                    }
                }
            }
            catch
            {
                throw new Exception("(ErrorCode:4) Network Or Service not Available");
            }
        }
Esempio n. 10
0
        public AccountStatement GetAccountStatement(DateTime From, DateTime To)
        {
            if (driver != null)
            {
                try {
                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_menu");
                    driver.FindElementById("RRAAClink").Click();

                    driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    driver.SwitchTo().Frame("frame_txn");

                    SelectElement elem = new SelectElement(driver.FindElementByName("fldacctno"));
                    elem.SelectByValue(this.Account_Value);

                    //driver.SwitchTo().Window(driver.CurrentWindowHandle);
                    //driver.SwitchTo().Frame("frame_txn");
                    var abcd = driver.FindElementsByClassName("objselect");

                    SelectElement elem2 = new SelectElement(abcd[1]);
                    elem2.SelectByValue("3");

                    driver.FindElementById("fldfromdateid").SendKeys(From.ToString("dd-MM-yyyy"));
                    driver.FindElementById("fldtodateid").SendKeys(To.ToString("dd-MM-yyyy"));

                    driver.FindElementByName("fldsubmit").Click();

                    var      alltables = driver.FindElementsByClassName("graphtable");
                    string   abc       = alltables[0].GetAttribute("innerHTML");
                    Document body      = Supremes.Dcsoup.Parse(abc);

                    AccountStatement statement = new AccountStatement();
                    statement.OpeningBalance = HelpingClass.ToDouble(body.Body.TextNodes[4].Text);
                    statement.ClosingBalance = HelpingClass.ToDouble(body.Body.TextNodes[5].Text);

                    abc  = alltables[1].GetAttribute("innerHTML");
                    body = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");

                    List <AccountActivity> activities = new List <AccountActivity>();
                    AccountActivity        activity   = new AccountActivity();

                    Elements trs = body.Select("tr");
                    Elements tds = null;

                    bool isavilable = false;

                    abc  = driver.FindElementByClassName("standardtable").GetAttribute("innerHTML");
                    body = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");
                    string[] arr         = body.Body.Text.Split(new string[] { "Pages : (" }, StringSplitOptions.None);
                    int      totalpage   = Convert.ToInt32(arr[1].Split(')')[0].Trim());
                    int      currentpage = 1;
                    do
                    {
                        for (int i = 0; i < trs.Count; i++)
                        {
                            if (i != 0)
                            {
                                tds      = trs[i].Select("td");
                                activity = new AccountActivity();

                                activity.TransactionDate        = DateTime.ParseExact(tds[0].OwnText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                                activity.ValueDate              = DateTime.ParseExact(tds[1].OwnText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                                activity.TransactionReferenceNo = tds[2].OwnText;
                                activity.Description            = tds[3].OwnText;
                                activity.Debit   = HelpingClass.ToDouble(tds[4].OwnText);
                                activity.Credit  = HelpingClass.ToDouble(tds[5].OwnText);
                                activity.Balance = HelpingClass.ToDouble(tds[6].OwnText);

                                activities.Add(activity);
                            }
                        }

                        if (currentpage < totalpage)
                        {
                            currentpage++;
                            driver.FindElementByCssSelector("a[href=\"javascript:SendPageRequest(" + currentpage.ToString() + ")\"]").Click();

                            alltables = driver.FindElementsByClassName("graphtable");
                            abc       = alltables[1].GetAttribute("innerHTML");
                            body      = Supremes.Dcsoup.ParseBodyFragment("<table>" + abc + "</table>");

                            trs        = body.Select("tr");
                            isavilable = true;
                        }
                        else
                        {
                            isavilable = false;
                        }
                    } while (isavilable);

                    statement.Activities = activities.AsReadOnly();

                    return(statement);
                }

                catch
                {
                    throw new Exception("(ErrorCode:11) Network Or Service is not available Or May be Problem occured While Fetching Account Details Try Again..");
                }
            }

            else
            {
                throw new Exception("(ErrorCode:10) Account Detail object not initialized");
            }
        }
Esempio n. 11
0
 public bool IsCheckedByName(string inputName)
 {
     return(_driver.FindElementByName(inputName).Selected);
 }