예제 #1
0
        public void WaitFor(Func <bool> condition, string description, int maxWaitMs = 15000)
        {
            Trace.TraceInformation("waiting for {0}...", description);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.ElapsedMilliseconds < maxWaitMs)
            {
                if (condition())
                {
                    Trace.TraceInformation(
                        "finished waiting for {0} after {1}ms",
                        description,
                        stopwatch.ElapsedMilliseconds);
                    return;
                }

                Trace.TraceWarning("still waiting for {0}...", description);
                BotDetectionMitigation.RandomizedWait();
            }

            stopwatch.Stop();
            Trace.TraceError(
                "gave up waiting for {0} after {1}ms",
                description,
                stopwatch.ElapsedMilliseconds);
        }
예제 #2
0
        private void CloseTabWithUrlContains(string partialUrl, int maxWaitMs = 15000)
        {
            string matchingWindowHandle = null;

            this.WaitFor(() =>
            {
                foreach (var windowHandle in this.Driver.WindowHandles)
                {
                    if (this.Driver.SwitchTo().Window(windowHandle).Url.Contains(partialUrl))
                    {
                        matchingWindowHandle = windowHandle;
                        break;
                    }
                }

                return(matchingWindowHandle != null);
            }, "tab to appear");

            while (this.Driver.WindowHandles.Contains(matchingWindowHandle))
            {
                this.Driver.SwitchTo().Window(matchingWindowHandle);
                this.Driver.Close();
                BotDetectionMitigation.RandomizedWait();
            }

            this.Driver.SwitchTo().Window(this.Driver.WindowHandles[0]);
        }
예제 #3
0
        private bool Click(IWebElement element)
        {
            bool clicked = false;

            Trace.TraceInformation("clicking {0}...", element.TagName);

            this.WaitFor(() => element.Displayed, "element to be visible");

            if (element.Displayed)
            {
                element.Click();
                clicked = true;
                BotDetectionMitigation.RandomizedWait();
            }

            Trace.TraceInformation("clicked = {0}", clicked);
            return(clicked);
        }