/// <summary> /// Type a text using random intervals /// </summary> /// <param name="page">"\_(^_^)_/"</param> /// <param name="selector">Query selector</param> /// <param name="text">Text to write down</param> /// <param name="minimumDelay">Minimum type interval</param> /// <param name="maximumDelay">Maximum type interval</param> /// <param name="random">Random generator</param> /// <param name="cancellationToken">Cancellation token</param> public static async Task TypeAsync(IPage page, string selector, string text, int minimumDelay = 50, int maximumDelay = 300, Random random = default, CancellationToken cancellationToken = default) { IElementHandle handle = await page.QuerySelectorAsync(selector) .ConfigureAwait(false); if (handle == null) { return; } if (random == null) { random = new Random(); } for (int i = 0; i < text.Length; i++) { await TaskUtils.RandomDelay(random, minimumDelay, maximumDelay, cancellationToken) .ConfigureAwait(false); await handle.PressAsync(text[i].ToString(), TaskUtils.GetRandomDelay(random, (minimumDelay / 2), minimumDelay)) .ConfigureAwait(false); } }
public async Task <string> CreateSelectorAsync(string name, IElementHandle elementHandle) { var mainContext = await((ElementHandle)elementHandle).Page.MainFrame.GetMainContextAsync().ConfigureAwait(false); return(await mainContext.EvaluateAsync <string>( @"(injected, target, name) => { return injected.engines.get(name).create(document.documentElement, target); }", await mainContext.GetInjectedAsync().ConfigureAwait(false), elementHandle, name).ConfigureAwait(false)); }
private async Task <string> GetPhoto(IElementHandle element) { var photoTag = await element.QuerySelectorAsync("img.gs-image"); if (photoTag != null) { return(await photoTag.EvaluateAsync <string>("e => e.getAttribute('src')")); } else { return(string.Empty); } }
private async Task WithElementAsync <TOptions>(Func <IElementHandle, TOptions, Task> callback, TOptions options) where TOptions : class { IElementHandle handle = await ElementHandleAsync(ConvertOptions <LocatorElementHandleOptions>(options)).ConfigureAwait(false); try { await callback(handle, options).ConfigureAwait(false); } finally { await handle.DisposeAsync().ConfigureAwait(false); } }
public async Task <IElementHandle> QuerySelectorAsync(string selector, IElementHandle scope = null) { var handle = await EvaluateHandleAsync( "(injected, selector, scope) => injected.querySelector(selector, scope || document)", await GetInjectedAsync().ConfigureAwait(false), Dom.NormalizeSelector(selector), scope).ConfigureAwait(false); if (!(handle is ElementHandle)) { await handle.DisposeAsync().ConfigureAwait(false); } return(handle as ElementHandle); }
static async Task AssertInput(IElementHandle input, string expectedValue, bool?expectError) { var value = await input.GetAttributeAsync("value"); Assert.Equal(expectedValue, value); var classes = await input.GetClassListAsync(); if (expectError == true) { Assert.Contains("govuk-input--error", classes); } else if (expectError == false) { Assert.DoesNotContain("govuk-input--error", classes); } }
private async Task <TEntity> GetDataAsync(IElementHandle element) { var entity = new TEntity(); var title = await element.QuerySelectorAsync("a.gs-title"); if (title == null) { return(entity); } entity.Url = await title.EvaluateAsync <string>("e => e.getAttribute('href')"); var innerText = await element.EvaluateAsync <string>("e => e.innerText"); entity.Description = innerText; entity.Photo = await GetPhoto(element); return(entity); }
public IElementHandle Create(IMachineElement element, MDE.ElementHandle type = MDE.ElementHandle.Position) { IElementHandle handle = null; if ((element != null) && !string.IsNullOrEmpty(element.ModelFile)) { switch (type) { case MDE.ElementHandle.Position: handle = CreatePositionElementHandle(element); break; case MDE.ElementHandle.Rotation: handle = CreaterRotationElementHandle(element); break; default: break; } } return(handle); }
/// <inheritdoc /> public Task <string[]> SelectAsync(string selector, IElementHandle value, WaitForSelectorOptions options = null) => throw new NotImplementedException();
public static async Task <string[]> GetClassListAsync(this IElementHandle element) { var classes = await element.GetAttributeAsync("class"); return(classes.Split(' ', System.StringSplitOptions.RemoveEmptyEntries)); }
public Task <SerializedAXNode> SnapshotAsync(bool interestingOnly = true, IElementHandle root = null) => _channel.AccessibilitySnapshotAsync(interestingOnly, (root as ElementHandle)?.ElementChannel);
public ElementWrapper(IElementHandle element, IFrameWrapper frame) { this.element = element; this.frame = frame; }
public Task <AccessibilitySnapshotResult> SnapshotAsync(bool?interestingOnly = null, IElementHandle root = null) => _channel.AccessibilitySnapshotAsync(interestingOnly, (root as ElementHandle)?.ElementChannel);
/// <summary> /// Initializes a new instance of the <see cref="FileChooserEventArgs"/> class. /// </summary> /// <param name="element">The input element.</param> /// <param name="multiple">The multiple option.</param> public FileChooserEventArgs(IElementHandle element, bool multiple) { Element = element; Multiple = multiple; }
/// <inheritdoc /> public Task <IReadOnlyCollection <string> > SelectOptionAsync(IElementHandle values, bool?noWaitAfter, float?timeout) => SelectOptionAsync(new[] { values }, noWaitAfter, timeout);
/// <inheritdoc /> public Task <string[]> SelectOptionAsync(string selector, IElementHandle value, int?timeout = null, bool?noWaitAfter = null) => SelectOptionAsync(selector, new[] { value }, timeout, noWaitAfter);
public Task <AccessibilityTree> GetAccessibilityTreeAsync(IElementHandle needle) => GetAccessibilityTreeAsync(_session, needle);
private async Task GetData(IPage page, IElementHandle element) { var innerText = await element.EvaluateAsync <string>("e => e.innerText"); Console.WriteLine(innerText); }
/// <inheritdoc /> public Task <string[]> SelectAsync(IElementHandle value) => SelectInternalAsync(new[] { value });
public static Task <Result <IElementHandle, Error> > QuerySelector(this IElementHandle elementHandle, string selector) => from result in elementHandle.QuerySelectorAsync(selector) select result is not null ? Ok <IElementHandle, Error>(result)
/// <inheritdoc /> public Task <string[]> SelectAsync(string selector, IElementHandle value, WaitForSelectorOptions options = null) => SelectAsync(selector, new[] { value }, options);
private async Task <AccessibilityTree> GetAccessibilityTreeAsync(FirefoxSession session, IElementHandle needle) { string objectId = (needle as ElementHandle)?.RemoteObject.ObjectId; var result = await session.SendAsync(new AccessibilityGetFullAXTreeRequest { ObjectId = objectId, }).ConfigureAwait(false); var axNode = new FirefoxAXNode(result.Tree); return(new AccessibilityTree { Tree = axNode, Needle = needle != null?axNode.FindNeedle() : null, }); }
/// <inheritdoc /> public Task <string[]> SelectAsync(IElementHandle value) => throw new NotImplementedException();
public Task <IReadOnlyList <string> > SelectOptionAsync(IElementHandle values, ElementHandleSelectOptionOptions options = default) => _channel.SelectOptionAsync(new[] { values }, options?.NoWaitAfter, options?.Force, options?.Timeout);
/// <summary> /// Initializes a new instance of the <see cref="FileChooserEventArgs"/> class. /// </summary> /// <param name="page">The page this file chooser belongs to.</param> /// <param name="element">The input element.</param> /// <param name="multiple">The multiple option.</param> public FileChooserEventArgs(IPage page, IElementHandle element, bool multiple) { Page = page; Element = element; IsMultiple = multiple; }
public Task <IReadOnlyList <string> > SelectOptionAsync(IElementHandle values, LocatorSelectOptionOptions options = null) => _frame.SelectOptionAsync(_selector, values, ConvertOptions <FrameSelectOptionOptions>(options));