예제 #1
0
 private void EncashmentClick(GeckoElement clicked)
 {
     try {
         if (clicked.HasAttribute("id") && !clicked.HasAttribute("disabled"))
         {
             if (clicked.GetAttribute("id").Equals("next"))
             {
                 var login    = (GeckoInputElement)_browser.Document.GetElementById("login");
                 var password = (GeckoInputElement)_browser.Document.GetElementById("password");
                 _collector = Collector.FindCollector(login.Value, password.Value);
                 if (_collector.Id <= 0)
                 {
                     const string message = "Неправильный логин и/или пароль";
                     MessageBox.Show(message);
                 }
                 else
                 {
                     Util.NavigateTo(_browser, CurrentWindow.MakeEncashment);
                 }
             }
             else if (clicked.GetAttribute("id").Equals("back"))
             {
                 Util.NavigateTo(_browser, CurrentWindow.Main);
             }
         }
     } catch (Exception exception) {
         Log.Error(exception);
     }
 }
예제 #2
0
        protected void HandleDomClick(object sender, DomMouseEventArgs e)
        {
            if (sender == null || e == null || e.Target == null)
            {
                return;
            }

            GeckoElement elem = e.Target.CastToGeckoElement();
            int          hvo;

            if (TryGetHvo(elem, out hvo))
            {
                JumpToToolBasedOnHvo(hvo);
            }

            if (elem.TagName.Equals("input", StringComparison.InvariantCultureIgnoreCase) &&
                elem.GetAttribute("type").Equals("button", StringComparison.InvariantCultureIgnoreCase))
            {
                switch (elem.GetAttribute("name"))
                {
                case "ShowWordGrammarDetail":
                    ShowWordGrammarDetail(elem.GetAttribute("id"));
                    break;

                case "TryWordGrammarAgain":
                    TryWordGrammarAgain(elem.GetAttribute("id"));
                    break;

                case "GoToPreviousWordGrammarPage":
                    GoToPreviousWordGrammarPage();
                    break;
                }
            }
        }
예제 #3
0
        private void EnterNumberClick(GeckoElement clicked)
        {
            try {
                if (clicked.HasAttribute("id") && !clicked.HasAttribute("disabled"))
                {
                    if (clicked.GetAttribute("id").Equals("next"))
                    {
                        var input = (GeckoInputElement)_browser.Document.GetElementById("number");
                        _payment.nomer  = input.Value;
                        _payment.nomer2 = ""; // Todo Проверить наличие поля ввода второго номера и если такого поля нет только потом вставить пустую строку
                        Log.Debug(String.Format("Entered number {0}", input.Value));
                        Util.NavigateTo(_browser, CurrentWindow.Pay);
                    }
                    else if (clicked.GetAttribute("id").Equals("back"))
                    {
                        _payment.nomer  = "";
                        _payment.nomer2 = "";

                        Util.NavigateTo(_browser,
                                        _clickedTopButton
                                            ? CurrentWindow.Main
                                            : CurrentWindow.Dependent);
                    }
                }
            } catch (Exception exception) {
                Log.Error(exception);
            }
        }
예제 #4
0
        public string getBetResult()
        {
            GeckoElement lastChild = (GeckoElement)resultList.LastChild;
            string       color     = lastChild.GetAttribute("data-color");

            return(color);
        }
예제 #5
0
 private void MakeEncashmentClick(GeckoElement clicked)
 {
     try {
         if (clicked.HasAttribute("id") && !clicked.HasAttribute("disabled"))
         {
             if (clicked.GetAttribute("id").Equals("next"))
             {
             }
             else if (clicked.GetAttribute("id").Equals("back"))
             {
                 Util.NavigateTo(_browser, CurrentWindow.Main);
             }
         }
     } catch (Exception exception) {
         Log.Error(exception);
     }
 }
예제 #6
0
 private void DependentClick(GeckoElement clicked)
 {
     try {
         if (clicked.HasAttribute("id"))
         {
             if (clicked.GetAttribute("id").Equals("back"))
             {
                 Util.NavigateTo(_browser, CurrentWindow.Main);
             }
             else
             {
                 _payment.id_uslugi = short.Parse(clicked.GetAttribute("id"));
                 Log.Debug(String.Format("Clicked service with id {0}", clicked.GetAttribute("id")));
                 Util.NavigateTo(_browser, CurrentWindow.EnterNumber);
             }
         }
     } catch (Exception exception) {
         Log.Error(exception);
     }
 }
예제 #7
0
        public void JQueryExecutor_GetElementByJQuery_ScriptExecutesAndReturnsExpectedResult()
        {
            browser.TestLoadHtml(JQueryExecutorTestsHtml);

            var          executor = new Gecko.JQuery.JQueryExecutor(browser.Window);
            GeckoElement div      = null;

            Assert.DoesNotThrow(() => div = executor.GetElementByJQuery("$('#a')"));
            Assert.IsNotNull(div);
            Assert.AreEqual("DIV", div.TagName);
            Assert.AreEqual("a", div.GetAttribute("id"));
        }
예제 #8
0
 void OpenGeckoLinksInNewWindow(object sender, DomMouseEventArgs e)
 {
     if (sender != null && e != null && e.Target != null)
     {
         GeckoElement clicked = e.Target.CastToGeckoElement();
         if (clicked.TagName == "A")
         {
             e.Handled = true;
             System.Diagnostics.Process.Start(clicked.GetAttribute("href"));
         }
     }
 }
예제 #9
0
 private void PayClick(GeckoElement clicked)
 {
     try {
         if (clicked.HasAttribute("id") && !clicked.HasAttribute("disabled"))
         {
             if (clicked.GetAttribute("id").Equals("next"))
             {
                 _payment.Save();
                 _payment = new Payment();
                 Util.NavigateTo(_browser, CurrentWindow.Main);
             }
             else if (clicked.GetAttribute("id").Equals("back"))
             {
                 Util.NavigateTo(_browser, CurrentWindow.EnterNumber);
             }
             _cashCode.DisableBillTypes();
         }
     } catch (Exception exception) {
         Log.Error(exception);
     }
 }
예제 #10
0
        private void MainClick(GeckoElement clicked)
        {
            try {
                if (clicked.HasAttribute("data-type"))
                {
                    switch (clicked.GetAttribute("data-type"))
                    {
                    case "service":
                        short.TryParse(clicked.GetAttribute("id"), out _mainServiceId);
                        Log.Debug(String.Format("Clicked service with id {0}", clicked.GetAttribute("id")));
                        Util.NavigateTo(_browser, CurrentWindow.Dependent);
                        _clickedTopButton = false;
                        break;

                    case "top-service":
                        try {
                            _payment.id_uslugi = short.Parse(clicked.GetAttribute("id"));
                            Log.Debug(String.Format("Clicked top-service with id {0}", clicked.GetAttribute("id")));
                            Util.NavigateTo(_browser, CurrentWindow.EnterNumber);
                            _clickedTopButton = true;
                        } catch (Exception ex) {
                            Log.Error("Incorrect service id format", ex, clicked);
                        }
                        break;

                    default:
                        Log.Debug("Clicked element was null");
                        return;
                    }
                }
                else if (clicked.HasAttribute("language"))
                {
                }
            } catch (Exception exception) {
                Log.Error(exception);
            }
        }
예제 #11
0
        protected bool TryGetHvo(GeckoElement element, out int hvo)
        {
            while (element != null)
            {
                switch (element.TagName.ToLowerInvariant())
                {
                case "table":
                case "span":
                case "th":
                case "td":
                    string id = element.GetAttribute("id");
                    if (!string.IsNullOrEmpty(id))
                    {
                        return(int.TryParse(id, out hvo));
                    }
                    break;
                }
                element = element.ParentElement;
            }

            hvo = 0;
            return(false);
        }
예제 #12
0
        private void LoadSearchParameters(Point point)
        {
            GeckoElement element = wbElementRecorder.DomDocument.ElementFromPoint(point.X, point.Y);

            string savedId  = element.GetAttribute("id");
            string uniqueId = Guid.NewGuid().ToString();

            element.SetAttribute("id", uniqueId);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(element.OwnerDocument.GetElementsByTagName("html")[0].OuterHtml);
            element.SetAttribute("id", savedId);
            HtmlNode node = doc.GetElementbyId(uniqueId);

            _xPath        = node.XPath.Replace("[1]", "");
            _name         = element.GetAttribute("name") == null ? "" : element.GetAttribute("name");
            _id           = element.GetAttribute("id") == null ? "" : element.GetAttribute("id");;
            _tagName      = element.TagName;
            _className    = element.GetAttribute("class") == null ? "" : element.GetAttribute("class");
            _linkText     = element.TagName.ToLower() != "a" ? "" : element.TextContent;
            _cssSelectors = GetCSSSelectors(element);

            string cssSelectorString = string.Join(", ", GetCSSSelectors(element));

            LastItemClicked   = $"[XPath:{_xPath}].[ID:{_id}].[Name:{_name}].[Tag Name:{_tagName}].[Class:{_className}].[Link Text:{_linkText}].[CSS Selector:{cssSelectorString}]";
            lblSubHeader.Text = LastItemClicked;

            SearchParameters = NewSearchParameterDataTable();
            if (IsRecordingSequence)
            {
                foreach (DataRow row in _parameterSettings.Rows)
                {
                    switch (row[1].ToString())
                    {
                    case "XPath":
                        SearchParameters.Rows.Add(row[0], "\"XPath\"", $"\"{_xPath}\"");
                        break;

                    case "ID":
                        SearchParameters.Rows.Add(row[0], "\"ID\"", $"\"{_id}\"");
                        break;

                    case "Name":
                        SearchParameters.Rows.Add(row[0], "\"Name\"", $"\"{_name}\"");
                        break;

                    case "Tag Name":
                        SearchParameters.Rows.Add(row[0], "\"Tag Name\"", $"\"{_tagName}\"");
                        break;

                    case "Class Name":
                        SearchParameters.Rows.Add(row[0], "\"Class Name\"", $"\"{_className}\"");
                        break;

                    case "Link Text":
                        SearchParameters.Rows.Add(row[0], "\"Link Text\"", $"\"{_linkText}\"");
                        break;

                    case "CSS Selector":
                        for (int i = 0; i < _cssSelectors.Count; i++)
                        {
                            SearchParameters.Rows.Add(row[0], $"\"CSS Selector {i + 1}\"", $"\"{_cssSelectors[i]}\"");
                        }
                        break;
                    }
                }
            }
            else
            {
                SearchParameters.Rows.Add(true, "\"XPath\"", $"\"{_xPath}\"");
                SearchParameters.Rows.Add(false, "\"ID\"", $"\"{_id}\"");
                SearchParameters.Rows.Add(false, "\"Name\"", $"\"{_name}\"");
                SearchParameters.Rows.Add(false, "\"Tag Name\"", $"\"{_tagName}\"");
                SearchParameters.Rows.Add(false, "\"Class Name\"", $"\"{_className}\"");
                SearchParameters.Rows.Add(false, "\"Link Text\"", $"\"{_linkText}\"");
                for (int i = 0; i < _cssSelectors.Count; i++)
                {
                    SearchParameters.Rows.Add(false, $"\"CSS Selector {i + 1}\"", $"\"{_cssSelectors[i]}\"");
                }
            }
        }
예제 #13
0
        /// <summary>
        /// An example event handler for the DomClick event.
        /// Prevents a link click from navigating.
        /// </summary>
        void StopLinksNavigating(object sender, GeckoDomEventArgs e)
        {
            if (sender != null && e != null && e.Target != null && e.Target.TagName != null)
            {
                GeckoElement clicked = e.Target;

                // prevent clicking on Links from navigation to the
                if (clicked.TagName == "A")
                {
                    e.Handled = true;
                    MessageBox.Show(sender as IWin32Window, String.Format("You clicked on Link {0}", clicked.GetAttribute("href")));
                }
            }
        }
예제 #14
0
        private void initializeElements()
        {
            usernameElement = (GeckoElement)browser.Document.GetElementsByClassName("username")[0];
            creditElement   = (GeckoElement)browser.Document.GetElementsByClassName("credits")[0];

            GeckoElement textboxParent = (GeckoElement)browser.Document.GetElementsByClassName("bet_system")[0];

            foreach (GeckoNode child in textboxParent.ChildNodes)
            {
                if (child.NodeName.ToLower() == "input")
                {
                    textboxElement = (GeckoInputElement)child;
                }
            }

            GeckoNode redDiv = browser.Document.GetElementsByClassName("table")[0];

            foreach (GeckoNode child in redDiv.ChildNodes)
            {
                if (NodeType.Element == child.NodeType)
                {
                    GeckoElement convert = (GeckoElement)child;
                    if (convert.GetAttribute("data-color") == "red")
                    {
                        redButton = (GeckoHtmlElement)child;
                        Console.WriteLine("Got Red");
                    }
                }
            }

            GeckoNode blackDiv = browser.Document.GetElementsByClassName("table")[2];

            foreach (GeckoNode child in blackDiv.ChildNodes)
            {
                if (NodeType.Element == child.NodeType)
                {
                    GeckoElement convert = (GeckoElement)child;
                    if (convert.GetAttribute("data-color") == "black")
                    {
                        blackButton = (GeckoHtmlElement)child;
                        Console.WriteLine("Got Black");
                    }
                }
            }

            GeckoNode resultListParent = browser.Document.GetElementsByClassName("winner_history")[0];

            foreach (GeckoNode child in resultListParent.ChildNodes)
            {
                if (NodeType.Element == child.NodeType)
                {
                    GeckoElement convert = (GeckoElement)child;
                    if (convert.GetAttribute("class") == "holder")
                    {
                        resultList = (GeckoElement)child;
                    }
                }
            }

            GeckoNode statusTextParent = browser.Document.GetElementsByClassName("roll_timer")[0];

            foreach (GeckoNode child in statusTextParent.ChildNodes)
            {
                if (NodeType.Element == child.NodeType)
                {
                    GeckoElement convert = (GeckoElement)child;
                    if (convert.GetAttribute("class") == "bg")
                    {
                        statusText = (GeckoElement)child;
                    }
                }
            }

            betRedStatusText   = (GeckoElement)browser.Document.GetElementsByClassName("your")[0];
            betBlackStatusText = (GeckoElement)browser.Document.GetElementsByClassName("your")[2];
        }
예제 #15
0
        private bool IsImageUrl(GeckoElement element)
        {
            string text = element.GetAttribute("data-image-url");

            return(!text.IsNullOrEmpty() && text.Contains("twimg.com"));
        }