Пример #1
0
        /// <summary>
        /// Scrolls element into view if needed, and then uses <see cref="Page.Mouse"/> to click in the center of the element.
        /// </summary>
        /// <param name="options">click options</param>
        /// <exception cref="PuppeteerException">if the element is detached from DOM</exception>
        /// <returns>Task which resolves when the element is successfully clicked</returns>
        public async Task ClickAsync(ClickOptions options = null)
        {
            await ScrollIntoViewIfNeededAsync().ConfigureAwait(false);

            var(x, y) = await ClickablePointAsync().ConfigureAwait(false);

            await Page.Mouse.ClickAsync(x, y, options).ConfigureAwait(false);
        }
Пример #2
0
        /// <inheritdoc cref="IMouse.UpAsync(ClickOptions)"/>
        public Task UpAsync(ClickOptions options = null)
        {
            var button     = options?.Button ?? MouseButton.Left;
            int clickCount = options?.ClickCount ?? 1;

            _lastButton = MouseButton.None;
            _buttons.Remove(button);
            return(_raw.UpAsync(_x, _y, button, _buttons, _keyboard.Modifiers, clickCount));
        }
Пример #3
0
    public void handleClick(string action)
    {
        clickDetector.overlayClicked = true;
        ClickOptions.clear();

        Debug.Log("clicked button: " + action + " parent: " + parentObj);

        ((clickable)parentObj.gameObject.GetComponent(typeof(clickable))).handleOption(action);
    }
Пример #4
0
        /// <inheritdoc cref="IMouse.DownAsync(ClickOptions)"/>
        public Task DownAsync(ClickOptions options = null)
        {
            var button     = options?.Button ?? MouseButton.Left;
            int clickCount = options?.ClickCount ?? 1;

            _lastButton = button;
            _buttons.Add(button);

            return(_raw.DownAsync(_x, _y, _lastButton, _buttons, _keyboard.Modifiers, clickCount));
        }
Пример #5
0
        internal async Task ClickAsync(string selector, ClickOptions options = null)
        {
            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);

            if (handle == null)
            {
                throw new SelectorException($"No node found for selector: {selector}", selector);
            }
            await handle.ClickAsync(options).ConfigureAwait(false);

            await handle.DisposeAsync().ConfigureAwait(false);
        }
Пример #6
0
        public VkontakteBrw(bool mobile)
        {
            Mobile    = mobile;
            BaseUrl   = mobile ? "https://m.vk.com" : "https://vk.com";
            UserAgent = Mobile ?
                        "Mozilla / 5.0(Linux; Android 4.2.1; en - us; Nexus 5 Build / JOP40D) AppleWebKit / 535.19(KHTML, like Gecko; googleweblight) Chrome / 38.0.1025.166 Mobile Safari/ 535.19" :
                        "Mozilla / 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 74.0.3723.0 Safari / 537.36";

            DefaultNavigationOptions = new NavigationOptions {
                Timeout = 30000
            };
            DefaultWaitForSelectorOptions = new WaitForSelectorOptions {
                Timeout = 10000
            };
            DefaultClickOptions = new ClickOptions {
                Delay = new Random().Next(100, 200)
            };
        }
Пример #7
0
        /// <inheritdoc cref="IMouse.ClickAsync(double, double, ClickOptions)"/>
        public async Task ClickAsync(double x, double y, ClickOptions options = null)
        {
            if ((options?.Delay ?? 0) != 0)
            {
                await Task.WhenAll(
                    MoveAsync(x, y),
                    DownAsync(options)).ConfigureAwait(false);

                await Task.Delay(options.Delay).ConfigureAwait(false);

                await UpAsync(options).ConfigureAwait(false);
            }
            else
            {
                await Task.WhenAll(
                    MoveAsync(x, y),
                    DownAsync(options),
                    UpAsync(options)).ConfigureAwait(false);
            }
        }
Пример #8
0
        /// <summary>
        /// Scrolls element into view if needed, and then uses <see cref="Page.Mouse"/> to click in the center of the element.
        /// </summary>
        /// <param name="options">click options</param>
        /// <exception cref="PuppeteerException">if the element is detached from DOM</exception>
        /// <returns>Task which resolves when the element is successfully clicked</returns>
        public async Task ClickAsync(ClickOptions options = null)
        {
            var(x, y) = await VisibleCenterAsync();

            await Page.Mouse.ClickAsync(x, y, options);
        }
Пример #9
0
 /// <summary>
 /// Fetches an element with <paramref name="selector"/>, scrolls it into view if needed, and then uses <see cref="Page.Mouse"/> to click in the center of the element.
 /// </summary>
 /// <param name="selector">A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.</param>
 /// <param name="options">click options</param>
 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>
 /// <returns>Task which resolves when the element matching <paramref name="selector"/> is successfully clicked</returns>
 public Task ClickAsync(string selector, ClickOptions options = null)
 => SecondaryWorld.ClickAsync(selector, options);
Пример #10
0
        /// <summary>
        /// Scrolls element into view if needed, and then uses <see cref="Page.Mouse"/> to click in the center of the element.
        /// </summary>
        /// <param name="options">click options</param>
        /// <exception cref="PuppeteerException">if the element is detached from DOM</exception>
        /// <returns>Task which resolves when the element is successfully clicked</returns>
        public async Task ClickAsync(ClickOptions options = null)
        {
            var(x, y) = await VisibleCenterAsync().ConfigureAwait(false);

            await Page.Mouse.ClickAsync(x, y, options).ConfigureAwait(false);
        }
Пример #11
0
 public static void clearPopUps()
 {
     ClickOptions.clear();
 }
Пример #12
0
        public async Task <List <VkBrwCommunity> > GetCommunities(BrowserContext userContext, Page userPage, VkBrwUser user)
        {
            List <VkBrwCommunity> nwPages = new List <VkBrwCommunity>();

            await userPage.GoToAsync(user.ProfileLink);

            ElementHandle userIsLoaded = await userPage.WaitForSelectorAsync("#page_info_wrap.page_info_wrap");

            ElementHandle[] hiddenProfileBlock = await userPage.QuerySelectorAllAsync("h5.profile_deleted_text");

            if (hiddenProfileBlock.Length == 0)
            {
                ElementHandle idolsLoaded = await userPage.WaitForSelectorAsync("#profile_idols");

                // Интересные страницы
                ElementHandle[] noteworthyPagesBlock = await userPage.QuerySelectorAllAsync("#profile_idols.module.clear.page_list_module._module");

                if (noteworthyPagesBlock.Length == 1)
                {
                    ElementHandle   noteworthyPages            = noteworthyPagesBlock.First();
                    ElementHandle[] noteworthyPagesHeaderBlock = await noteworthyPages.QuerySelectorAllAsync("a.module_header");

                    if (noteworthyPagesHeaderBlock.Length == 1)
                    {
                        ClickOptions clickOptions = new ClickOptions {
                            Delay = new Random().Next(30, 100)
                        };

                        ElementHandle noteworthyPagesLinkElement = noteworthyPagesHeaderBlock.First();
                        await noteworthyPagesLinkElement.ClickAsync(clickOptions);

                        ElementHandle noteworthyPagesIsOpened = await userPage.WaitForSelectorAsync("#fans_rowsidols.fans_rows.fans_idols");

                        ElementHandle[] closeBlock = await userPage.QuerySelectorAllAsync("div.box_x_button");

                        if (closeBlock.Length == 1)
                        {
                            ElementHandle[] pagesCountBlock = await userPage.QuerySelectorAllAsync("span.ui_box_header_cnt");

                            if (pagesCountBlock.Length == 1)
                            {
                                ElementHandle pagesTotalCountElement = pagesCountBlock.First();
                                string        pagesTotalCountValue   = await pagesTotalCountElement.EvaluateFunctionAsync <string>("('span', span => span.innerText)");

                                if (!string.IsNullOrEmpty(pagesTotalCountValue))
                                {
                                    bool pagesTotalCountReceived = int.TryParse(pagesTotalCountValue, out int pagesTotalCount);

                                    if (pagesTotalCountReceived && pagesTotalCount > 0)
                                    {
                                        ElementHandle[] pagesVisibleElements = await userPage.QuerySelectorAllAsync("div.fans_idol_row.inl_bl");

                                        if (pagesVisibleElements.Length < pagesTotalCount)
                                        {
                                            PressOptions pressOptions = new PressOptions {
                                                Delay = new Random().Next(20, 40)
                                            };

                                            await userPage.FocusAsync("input");

                                            await userPage.Keyboard.PressAsync("Tab", pressOptions);

                                            int visiblePagesCounter = pagesVisibleElements.Length;

                                            while (visiblePagesCounter < pagesTotalCount)
                                            {
                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                await userPage.Keyboard.PressAsync("PageDown", pressOptions);

                                                await Task.Delay(new Random().Next(250, 350));

                                                ElementHandle[] newPagesVisibleElements = await userPage.QuerySelectorAllAsync("div.fans_idol_row.inl_bl");

                                                if (newPagesVisibleElements.Length == visiblePagesCounter)
                                                {
                                                    break;
                                                }

                                                visiblePagesCounter = newPagesVisibleElements.Length;
                                            }
                                        }

                                        ElementHandle[] nwPagesElements = await userPage.QuerySelectorAllAsync("div.fans_idol_info");

                                        foreach (var element in nwPagesElements)
                                        {
                                            VkBrwCommunity community = await GetCommunityAsync(element, userContext);

                                            if (community != null)
                                            {
                                                nwPages.Add(community);
                                                community.Users.Add(user);
                                            }
                                        }
                                    }
                                }
                            }

                            ElementHandle closeButtonElement = closeBlock.First();
                            await closeButtonElement.ClickAsync(clickOptions);
                        }
                    }
                }
            }
            else
            {
                user.HiddenProfile = true;

                ElementHandle[] pageNameElements = await userPage.QuerySelectorAllAsync("h2.page_name");

                if (pageNameElements.Length == 1)
                {
                    var pageElement = pageNameElements.First();
                    user.PageName = await pageElement.EvaluateFunctionAsync <string>("('h2', h2 => h2.innerText)");
                }
            }

            return(nwPages);
        }
Пример #13
0
        /// <summary>
        /// click element
        /// </summary>
        /// <returns></returns>
        public bool Click(ClickOptions option = ClickOptions.CenterElement)
        {
            AutomationElement element = GetCurrentAutoElement();

            return(Click(element, option));
        }