/// <inheritdoc cref="IKeyboard.PressAsync(string, PressOptions)"/> public async Task PressAsync(string key, PressOptions options = null) { int delay = options?.Delay ?? 0; await DownAsync(key, options).ConfigureAwait(false); if (delay != 0) { await Task.Delay(delay).ConfigureAwait(false); } await UpAsync(key).ConfigureAwait(false); }
/// <summary> /// Focuses the element, and then uses <see cref="Keyboard.DownAsync(string, DownOptions)"/> and <see cref="Keyboard.UpAsync(string)"/>. /// </summary> /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. See <see cref="KeyDefinitions"/> for a list of all key names.</param> /// <param name="options">press options</param> /// <remarks> /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also be generated. The <see cref="DownOptions.Text"/> option can be specified to force an input event to be generated. /// </remarks> /// <returns></returns> public async Task PressAsync(string key, PressOptions options = null) { await FocusAsync(); await Page.Keyboard.PressAsync(key, options); }
/// <summary> /// Focuses the element, and then uses <see cref="Keyboard.DownAsync(string, DownOptions)"/> and <see cref="Keyboard.UpAsync(string)"/>. /// </summary> /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. See <see cref="KeyDefinitions"/> for a list of all key names.</param> /// <param name="options">press options</param> /// <remarks> /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also be generated. The <see cref="DownOptions.Text"/> option can be specified to force an input event to be generated. /// </remarks> /// <returns></returns> public async Task PressAsync(string key, PressOptions options = null) { await FocusAsync().ConfigureAwait(false); await Page.Keyboard.PressAsync(key, options).ConfigureAwait(false); }
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); }
/// <inheritdoc cref="IKeyboard.PressAsync(string, PressOptions)"/> public Task PressAsync(string key, PressOptions options = null) { throw new NotImplementedException(); }