internal void Detach() { Detached = true; MainWorld.Detach(); SecondaryWorld.Detach(); if (ParentFrame != null) { ParentFrame.ChildFrames.Remove(this); } ParentFrame = null; }
/// <summary> /// Waits for a selector to be added to the DOM /// </summary> /// <param name="xpath">A xpath selector of an element to wait for</param> /// <param name="options">Optional waiting parameters</param> /// <returns>A task which resolves when element specified by xpath string is added to DOM. /// Resolves to `null` if waiting for `hidden: true` and xpath is not found in DOM.</returns> /// <example> /// <code> /// <![CDATA[ /// var browser = await Puppeteer.LaunchAsync(new LaunchOptions()); /// var page = await browser.NewPageAsync(); /// string currentURL = null; /// page.MainFrame /// .WaitForXPathAsync("//img") /// .ContinueWith(_ => Console.WriteLine("First URL with image: " + currentURL)); /// foreach (var current in new[] { "https://example.com", "https://google.com", "https://bbc.com" }) /// { /// currentURL = current; /// await page.GoToAsync(currentURL); /// } /// await browser.CloseAsync(); /// ]]> /// </code> /// </example> /// <seealso cref="WaitForSelectorAsync(string, WaitForSelectorOptions)"/> /// <seealso cref="Page.WaitForXPathAsync(string, WaitForSelectorOptions)"/> /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception> public async Task <ElementHandle> WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null) { var handle = await SecondaryWorld.WaitForXPathAsync(xpath, options).ConfigureAwait(false); if (handle == null) { return(null); } var mainExecutionContext = await MainWorld.GetExecutionContextAsync().ConfigureAwait(false); var result = await mainExecutionContext.AdoptElementHandleASync(handle).ConfigureAwait(false); await handle.DisposeAsync().ConfigureAwait(false); return(result); }
/// <summary> /// Sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for each character in the text. /// </summary> /// <param name="selector">A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.</param> /// <param name="text">A text to type into a focused element</param> /// <param name="options"></param> /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception> /// <remarks> /// To press a special key, like <c>Control</c> or <c>ArrowDown</c> use <see cref="Keyboard.PressAsync(string, PressOptions)"/> /// </remarks> /// <example> /// <code> /// await frame.TypeAsync("#mytextarea", "Hello"); // Types instantly /// await frame.TypeAsync("#mytextarea", "World", new TypeOptions { Delay = 100 }); // Types slower, like a user /// </code> /// </example> /// <returns>Task</returns> public Task TypeAsync(string selector, string text, TypeOptions options = null) => SecondaryWorld.TypeAsync(selector, text, options);
/// <summary> /// Fetches an element with <paramref name="selector"/> and focuses it /// </summary> /// <param name="selector">A selector to search for element to focus. If there are multiple elements satisfying the selector, the first will be focused.</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 focused</returns> public Task FocusAsync(string selector) => SecondaryWorld.FocusAsync(selector);
/// <summary> /// Fetches an element with <paramref name="selector"/>, scrolls it into view if needed, and then uses <see cref="Page.Mouse"/> to hover over the center of the element. /// </summary> /// <param name="selector">A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.</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 hovered</returns> public Task HoverAsync(string selector) => SecondaryWorld.HoverAsync(selector);
/// <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);
/// <summary> /// Returns page's title /// </summary> /// <returns>page's title</returns> /// <seealso cref="Page.GetTitleAsync"/> public Task <string> GetTitleAsync() => SecondaryWorld.GetTitleAsync();
/// <summary> /// Sets the HTML markup to the page /// </summary> /// <param name="html">HTML markup to assign to the page.</param> /// <param name="options">The options</param> /// <returns>Task.</returns> /// <seealso cref="Page.SetContentAsync(string, NavigationOptions)"/> public Task SetContentAsync(string html, NavigationOptions options = null) => SecondaryWorld.SetContentAsync(html, options);
/// <summary> /// Gets the full HTML contents of the page, including the doctype. /// </summary> /// <returns>Task which resolves to the HTML content.</returns> /// <seealso cref="Page.GetContentAsync"/> public Task <string> GetContentAsync() => SecondaryWorld.GetContentAsync();
/// <summary> /// Triggers a change and input event once all the provided options have been selected. /// If there's no <![CDATA[<select>]]> element matching selector, the method throws an error. /// </summary> /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception> /// <param name="selector">A selector to query page for</param> /// <param name="values">Values of options to select. If the <![CDATA[<select>]]> has the multiple attribute, /// all values are considered, otherwise only the first one is taken into account.</param> /// <returns>Returns an array of option values that have been successfully selected.</returns> /// <seealso cref="Page.SelectAsync(string, string[])"/> public Task <string[]> SelectAsync(string selector, params string[] values) => SecondaryWorld.SelectAsync(selector, values);