Beispiel #1
0
    static void Main()
    {
        // Red text is for printing errors
        void RedMessage(string message)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.White;
        }

        // Green text is for printing successes
        void GreenMessage(string message)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.White;
        }

        RedMessage("Red Message Initialized");
        GreenMessage("Green Message Initialized");



        string      password = "******";
        string      username = "******";
        IWebDriver  driver   = new ChromeDriver();
        IWebElement UserName_TextBox;
        IWebElement Password_TextBox;
        IWebElement No_Save_Password;
        IWebElement GrandExchangeButton;

        GreenMessage("Initial_Setup Variables Successfully Initialized");

        void Initial_Setup()
        {
            try
            {
                driver.Navigate().GoToUrl("http://www.runescape.com/companion/comapp.ws");
                GreenMessage("Navigation Complete");
                Thread.Sleep(10000);
                GreenMessage("Wait for page to load");
                driver.SwitchTo().Frame(0);
                UserName_TextBox = driver.FindElement(By.Name("username"));
                UserName_TextBox.Click();
                UserName_TextBox.SendKeys(username);
                GreenMessage("Found Username Text Box");
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(0);
                Password_TextBox = driver.FindElement(By.Name("password"));
                Password_TextBox.Click();
                Password_TextBox.SendKeys(password);
                Password_TextBox.Submit();
                GreenMessage("Found Password Text Box");
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(0);
                GreenMessage("Wait for RS Authenticator");
                Thread.Sleep(20000);
                No_Save_Password = driver.FindElement(By.CssSelector("#modal > div > div > div > div.pill-wrap.double > a:nth-child(1)"));
                No_Save_Password.Click();
                GreenMessage("Don't save password clicked");
                Thread.Sleep(5000);
                GrandExchangeButton = driver.FindElement(By.CssSelector("#main-menu > div > nav > ul > li.grand-exchange > a"));
                GrandExchangeButton.Click();
                GreenMessage("Found GE Button on Main Menu");
                Thread.Sleep(5000);
            }
            catch (NoSuchElementException)
            {
                RedMessage("Initial Setup Failed");
            }
        }

        Initial_Setup();



        IWebElement Buy;
        IWebElement New_SearchBar;
        IWebElement New_MagicLogsButton;

        GreenMessage("Set_Price Variables Successfully Initialized");
        void Set_Price()
        {
            try
            {
                Buy = driver.FindElement(By.CssSelector("body > div.sliding-wrapper > div.ng-scope > section > div > ul > li:nth-child(1) > div > div > div.details.with-buttons > div > a:nth-child(1)"));
                Buy.Click();
                New_SearchBar = driver.FindElement(By.XPath("//*[@id=\"search\"]"));
                New_SearchBar.Click();
                New_SearchBar.SendKeys("Magic");
                Thread.Sleep(2000);
                New_SearchBar.SendKeys(" Logs");
                New_MagicLogsButton = driver.FindElement(By.CssSelector("body > div.sliding-wrapper > div.ng-scope > section > div.content.push-top-double.push-bottom-tiny.ng-scope > ul > li > a > div.details > span"));
                New_MagicLogsButton.Click();
            }
            catch (NoSuchElementException)
            {
                RedMessage("Set_Price Failed");
            }
        }

        /*
         * -------------------
         * MAIN LOOP -- MAIN LOOP
         * MAIN LOOP -- MAIN LOOP
         * MAIN LOOP -- MAIN LOOP
         * -------------------
         */



        /*
         * -------------------
         * MAIN LOOP -- MAIN LOOP
         * MAIN LOOP -- MAIN LOOP
         * MAIN LOOP -- MAIN LOOP
         * -------------------
         */
    }