diff --git a/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorTests.cs b/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorTests.cs index cd82f1377..811f10278 100644 --- a/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorTests.cs +++ b/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorTests.cs @@ -1,16 +1,11 @@ -using System; using System.Threading.Tasks; using NUnit.Framework; using PuppeteerSharp.Nunit; -namespace PuppeteerSharp.Tests.ElementHandleTests +namespace PuppeteerSharp.Tests.QuerySelectorTests { public class ElementHandleQuerySelectorTests : PuppeteerPageBaseTest { - public ElementHandleQuerySelectorTests() : base() - { - } - [Test, Retry(2), PuppeteerTest("queryselector.spec", "ElementHandle.$", "should query existing element")] public async Task ShouldQueryExistingElement() { @@ -31,5 +26,26 @@ public async Task ShouldReturnNullForNonExistingElement() var second = await html.QuerySelectorAsync(".third"); Assert.Null(second); } + + [Test, Retry(2), PuppeteerTest("queryselector.spec", "ElementHandle.$$ xpath", "should query existing element")] + public async Task XPathShouldQueryExistingElement() + { + await Page.GoToAsync(TestConstants.ServerUrl + "/playground.html"); + await Page.SetContentAsync("
A
"); + var html = await Page.QuerySelectorAsync("html"); + var second = await html.QuerySelectorAllAsync("xpath/./body/div[contains(@class, 'second')]"); + var inner = await second[0].QuerySelectorAllAsync("xpath/./div[contains(@class, 'inner')]"); + var content = await Page.EvaluateFunctionAsync("e => e.textContent", inner[0]); + Assert.AreEqual("A", content); + } + + [Test, Retry(2), PuppeteerTest("queryselector.spec", "ElementHandle.$$ xpath", "should return null for non-existing element")] + public async Task XPathShouldReturnNullForNonExistingElement() + { + await Page.SetContentAsync("
B
"); + var html = await Page.QuerySelectorAsync("html"); + var second = await html.QuerySelectorAllAsync("xpath/div[contains(@class, 'third')]"); + Assert.IsEmpty(second); + } } } diff --git a/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleXPathTests.cs b/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleXPathTests.cs deleted file mode 100644 index 054b879cd..000000000 --- a/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleXPathTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -#pragma warning disable CS0618 // XPathAsync is obsolete but we test the funcionatlity anyway -using System.Threading.Tasks; -using NUnit.Framework; -using PuppeteerSharp.Nunit; - -namespace PuppeteerSharp.Tests.ElementHandleTests -{ - public class ElementHandleXPathTests : PuppeteerPageBaseTest - { - public ElementHandleXPathTests() : base() - { - } - - [Test, Retry(2), PuppeteerTest("queryselector.spec", "ElementHandle.$x", "should query existing element")] - public async Task ShouldQueryExistingElement() - { - await Page.GoToAsync(TestConstants.ServerUrl + "/playground.html"); - await Page.SetContentAsync("
A
"); - var html = await Page.QuerySelectorAsync("html"); - var second = await html.XPathAsync("./body/div[contains(@class, 'second')]"); - var inner = await second[0].XPathAsync("./div[contains(@class, 'inner')]"); - var content = await Page.EvaluateFunctionAsync("e => e.textContent", inner[0]); - Assert.AreEqual("A", content); - } - - [Test, Retry(2), PuppeteerTest("queryselector.spec", "ElementHandle.$x", "should return null for non-existing element")] - public async Task ShouldReturnNullForNonExistingElement() - { - await Page.SetContentAsync("
B
"); - var html = await Page.QuerySelectorAsync("html"); - var second = await html.XPathAsync("/div[contains(@class, 'third')]"); - Assert.IsEmpty(second); - } - } -} -#pragma warning restore CS0618 diff --git a/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageQuerySelectorTests.cs b/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageQuerySelectorTests.cs index 4114036b4..1f36a769f 100644 --- a/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageQuerySelectorTests.cs +++ b/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageQuerySelectorTests.cs @@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.QuerySelectorTests { public class PageQuerySelectorTests : PuppeteerPageBaseTest { - public PageQuerySelectorTests() : base() - { - } - [Test, Retry(2), PuppeteerTest("queryselector.spec", "Page.$", "should query existing element")] public async Task ShouldQueryExistingElement() { @@ -24,5 +20,29 @@ public async Task ShouldReturnNullForNonExistingElement() var element = await Page.QuerySelectorAsync("non-existing-element"); Assert.Null(element); } + + [Test, Retry(2), PuppeteerTest("queryselector.spec", "querySelector Page.$$ xpath", "should query existing element")] + public async Task XPathShouldQueryExistingElement() + { + await Page.SetContentAsync("
test
"); + var elements = await Page.QuerySelectorAllAsync("xpath/html/body/section"); + Assert.NotNull(elements[0]); + Assert.That(elements, Has.Exactly(1).Items); + } + + [Test, Retry(2), PuppeteerTest("queryselector.spec", "querySelector Page.$$ xpath", "should return empty array for non-existing element")] + public async Task ShouldReturnEmptyArrayForNonExistingElement() + { + var elements = await Page.QuerySelectorAllAsync("xpath/html/body/non-existing-element"); + Assert.IsEmpty(elements); + } + + [Test, Retry(2), PuppeteerTest("queryselector.spec", "querySelector Page.$$ xpath", "should return multiple elements")] + public async Task XpathShouldReturnMultipleElements() + { + await Page.SetContentAsync("
"); + var elements = await Page.QuerySelectorAllAsync("xpath/html/body/div"); + Assert.AreEqual(2, elements.Length); + } } } diff --git a/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageXPathTests.cs b/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageXPathTests.cs deleted file mode 100644 index be2f2f997..000000000 --- a/lib/PuppeteerSharp.Tests/QuerySelectorTests/PageXPathTests.cs +++ /dev/null @@ -1,39 +0,0 @@ -#pragma warning disable CS0618 // WaitForXPathAsync is obsolete but we test the funcionatlity anyway -using System.Threading.Tasks; -using NUnit.Framework; -using PuppeteerSharp.Nunit; - -namespace PuppeteerSharp.Tests.QuerySelectorTests -{ - public class PageXPathTests : PuppeteerPageBaseTest - { - public PageXPathTests() : base() - { - } - - [Test, Retry(2), PuppeteerTest("queryselector.spec", "Page.$x", "should query existing element")] - public async Task ShouldQueryExistingElement() - { - await Page.SetContentAsync("
test
"); - var elements = await Page.XPathAsync("/html/body/section"); - Assert.NotNull(elements[0]); - Assert.That(elements, Has.Exactly(1).Items); - } - - [Test, Retry(2), PuppeteerTest("queryselector.spec", "Page.$x", "should return empty array for non-existing element")] - public async Task ShouldReturnEmptyArrayForNonExistingElement() - { - var elements = await Page.XPathAsync("/html/body/non-existing-element"); - Assert.IsEmpty(elements); - } - - [Test, Retry(2), PuppeteerTest("queryselector.spec", "Page.$x", "should return multiple elements")] - public async Task ShouldReturnMultipleElements() - { - await Page.SetContentAsync("
"); - var elements = await Page.XPathAsync("/html/body/div"); - Assert.AreEqual(2, elements.Length); - } - } -} -#pragma warning restore CS0618 diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForSelectorTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForSelectorTests.cs index e6b2915f0..a465f03a2 100644 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForSelectorTests.cs +++ b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForSelectorTests.cs @@ -1,14 +1,39 @@ -using System; using System.Linq; using System.Threading.Tasks; using NUnit.Framework; +using PuppeteerSharp.Helpers; using PuppeteerSharp.Nunit; +using PuppeteerSharp.Transport; namespace PuppeteerSharp.Tests.WaitTaskTests { public class FrameWaitForSelectorTests : PuppeteerPageBaseTest { private const string AddElement = "tag => document.body.appendChild(document.createElement(tag))"; + private PollerInterceptor _pollerInterceptor; + + public FrameWaitForSelectorTests() + { + DefaultOptions = TestConstants.DefaultBrowserOptions(); + + // Set up a custom TransportFactory to intercept sent messages + // Some of the tests require making assertions after a WaitForFunction has + // started, but before it has resolved. We detect that reliably by + // listening to the message that is sent to start polling. + // This might not be an issue in upstream puppeteer.js, or may be highly unlikely, + // due to differences between node.js's task scheduler and .net's. + DefaultOptions.TransportFactory = async (url, options, cancellationToken) => + { + _pollerInterceptor = new PollerInterceptor(await WebSocketTransport.DefaultTransportFactory(url, options, cancellationToken)); + return _pollerInterceptor; + }; + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + _pollerInterceptor.Dispose(); + } [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector", "should immediately resolve promise if node exists")] public async Task ShouldImmediatelyResolveTaskIfNodeExists() @@ -222,7 +247,7 @@ public async Task ShouldReturnNullIfWaitingToHideNonExistingElement() } [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector", "should respect timeout")] - public void ShouldRespectTimeout() + public void XpathShouldRespectTimeout() { var exception = Assert.ThrowsAsync(async () => await Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Timeout = 10 })); @@ -266,5 +291,88 @@ public void ShouldHaveCorrectStackTraceForTimeout() => await Page.WaitForSelectorAsync(".zombo", new WaitForSelectorOptions { Timeout = 10 })); StringAssert.Contains("WaitForSelectorTests", exception.StackTrace); } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should support some fancy xpath")] + public async Task ShouldSupportSomeFancyXpath() + { + await Page.SetContentAsync("

red herring

hello world

"); + var waitForXPath = Page.WaitForSelectorAsync("xpath/.//p[normalize-space(.)=\"hello world\"]"); + Assert.AreEqual("hello world ", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should run in specified frame")] + public async Task XpathShouldRunInSpecifiedFrame() + { + await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage); + await FrameUtils.AttachFrameAsync(Page, "frame2", TestConstants.EmptyPage); + var frame1 = Page.Frames.First(f => f.Name == "frame1"); + var frame2 = Page.Frames.First(f => f.Name == "frame2"); + var waitForXPathPromise = frame2.WaitForSelectorAsync("xpath/.//div"); + await frame1.EvaluateFunctionAsync(AddElement, "div"); + await frame2.EvaluateFunctionAsync(AddElement, "div"); + var eHandle = await waitForXPathPromise; + Assert.AreEqual(frame2, eHandle.Frame); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should throw when frame is detached")] + public async Task XpathShouldThrowWhenFrameIsDetached() + { + await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage); + var frame = Page.FirstChildFrame(); + var waitPromise = frame.WaitForSelectorAsync("xpath/.//*[@class=\"box\"]"); + await FrameUtils.DetachFrameAsync(Page, "frame1"); + var exception = Assert.ThrowsAsync(() => waitPromise); + StringAssert.Contains("waitForFunction failed: frame got detached.", exception.Message); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "hidden should wait for display: none")] + public async Task HiddenShouldWaitForDisplayNone() + { + var divHidden = false; + var startedPolling = _pollerInterceptor.WaitForStartPollingAsync(); + await Page.SetContentAsync("
"); + var waitForXPath = Page.WaitForSelectorAsync("xpath/.//div", new WaitForSelectorOptions { Hidden = true }) + .ContinueWith(_ => divHidden = true); + await startedPolling; + Assert.False(divHidden); + await Page.EvaluateExpressionAsync("document.querySelector('div').style.setProperty('display', 'none')"); + Assert.True(await waitForXPath.WithTimeout()); + Assert.True(divHidden); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should return the element handle")] + public async Task XpathShouldReturnTheElementHandle() + { + var waitForXPath = Page.WaitForSelectorAsync("xpath/.//*[@class=\"zombo\"]"); + await Page.SetContentAsync("
anything
"); + Assert.AreEqual("anything", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should allow you to select a text node")] + public async Task ShouldAllowYouToSelectATextNode() + { + await Page.SetContentAsync("
some text
"); + var text = await Page.WaitForSelectorAsync("xpath/.//div/text()"); + Assert.AreEqual(3 /* Node.TEXT_NODE */, await (await text.GetPropertyAsync("nodeType")).JsonValueAsync()); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should allow you to select an element with single slash")] + public async Task ShouldAllowYouToSelectAnElementWithSingleSlash() + { + await Page.SetContentAsync("
some text
"); + var waitForXPath = Page.WaitForSelectorAsync("xpath/html/body/div"); + Assert.AreEqual("some text", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); + } + + [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForSelector xpath", "should respect timeout")] + public void ShouldRespectTimeout() + { + const int timeout = 10; + + var exception = Assert.ThrowsAsync(() + => Page.WaitForSelectorAsync("xpath/.//div", new WaitForSelectorOptions { Timeout = timeout })); + + StringAssert.Contains($"Waiting failed: {timeout}ms exceeded", exception.Message); + } } } diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForXPathTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForXPathTests.cs deleted file mode 100644 index 8c6510ce9..000000000 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForXPathTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -#pragma warning disable CS0618 // WaitForXPathAsync is obsolete but we test the funcionatlity anyway -using System; -using System.Linq; -using System.Threading.Tasks; -using NUnit.Framework; -using PuppeteerSharp.Helpers; -using PuppeteerSharp.Nunit; -using PuppeteerSharp.Transport; - -namespace PuppeteerSharp.Tests.WaitTaskTests -{ - public sealed class FrameWaitForXPathTests : PuppeteerPageBaseTest - { - private const string AddElement = "tag => document.body.appendChild(document.createElement(tag))"; - private PollerInterceptor _pollerInterceptor; - - public FrameWaitForXPathTests() - { - DefaultOptions = TestConstants.DefaultBrowserOptions(); - - // Set up a custom TransportFactory to intercept sent messages - // Some of the tests require making assertions after a WaitForFunction has - // started, but before it has resolved. We detect that reliably by - // listening to the message that is sent to start polling. - // This might not be an issue in upstream puppeteer.js, or may be highly unlikely, - // due to differences between node.js's task scheduler and .net's. - DefaultOptions.TransportFactory = async (url, options, cancellationToken) => - { - _pollerInterceptor = new PollerInterceptor(await WebSocketTransport.DefaultTransportFactory(url, options, cancellationToken)); - return _pollerInterceptor; - }; - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - _pollerInterceptor.Dispose(); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should support some fancy xpath")] - public async Task ShouldSupportSomeFancyXpath() - { - await Page.SetContentAsync("

red herring

hello world

"); - var waitForXPath = Page.WaitForXPathAsync("//p[normalize-space(.)=\"hello world\"]"); - Assert.AreEqual("hello world ", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should run in specified frame")] - public async Task ShouldRunInSpecifiedFrame() - { - await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage); - await FrameUtils.AttachFrameAsync(Page, "frame2", TestConstants.EmptyPage); - var frame1 = Page.Frames.First(f => f.Name == "frame1"); - var frame2 = Page.Frames.First(f => f.Name == "frame2"); - var waitForXPathPromise = frame2.WaitForXPathAsync("//div"); - await frame1.EvaluateFunctionAsync(AddElement, "div"); - await frame2.EvaluateFunctionAsync(AddElement, "div"); - var eHandle = await waitForXPathPromise; - Assert.AreEqual(frame2, eHandle.Frame); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should throw when frame is detached")] - public async Task ShouldThrowWhenFrameIsDetached() - { - await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage); - var frame = Page.FirstChildFrame(); - var waitPromise = frame.WaitForXPathAsync("//*[@class=\"box\"]"); - await FrameUtils.DetachFrameAsync(Page, "frame1"); - var exception = Assert.ThrowsAsync(() => waitPromise); - StringAssert.Contains("waitForFunction failed: frame got detached.", exception.Message); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "hidden should wait for display: none")] - public async Task HiddenShouldWaitForDisplayNone() - { - var divHidden = false; - var startedPolling = _pollerInterceptor.WaitForStartPollingAsync(); - await Page.SetContentAsync("
"); - var waitForXPath = Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Hidden = true }) - .ContinueWith(_ => divHidden = true); - await startedPolling; - Assert.False(divHidden); - await Page.EvaluateExpressionAsync("document.querySelector('div').style.setProperty('display', 'none')"); - Assert.True(await waitForXPath.WithTimeout()); - Assert.True(divHidden); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should return the element handle")] - public async Task ShouldReturnTheElementHandle() - { - var waitForXPath = Page.WaitForXPathAsync("//*[@class=\"zombo\"]"); - await Page.SetContentAsync("
anything
"); - Assert.AreEqual("anything", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should allow you to select a text node")] - public async Task ShouldAllowYouToSelectATextNode() - { - await Page.SetContentAsync("
some text
"); - var text = await Page.WaitForXPathAsync("//div/text()"); - Assert.AreEqual(3 /* Node.TEXT_NODE */, await (await text.GetPropertyAsync("nodeType")).JsonValueAsync()); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should allow you to select an element with single slash")] - public async Task ShouldAllowYouToSelectAnElementWithSingleSlash() - { - await Page.SetContentAsync("
some text
"); - var waitForXPath = Page.WaitForXPathAsync("/html/body/div"); - Assert.AreEqual("some text", await Page.EvaluateFunctionAsync("x => x.textContent", await waitForXPath)); - } - - [Test, Retry(2), PuppeteerTest("waittask.spec", "waittask specs Frame.waitForXPath", "should respect timeout")] - public void ShouldRespectTimeout() - { - const int timeout = 10; - - var exception = Assert.ThrowsAsync(() - => Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Timeout = timeout })); - - StringAssert.Contains($"Waiting failed: {timeout}ms exceeded", exception.Message); - } - } -} -#pragma warning restore CS0618 diff --git a/lib/PuppeteerSharp/ElementHandle.cs b/lib/PuppeteerSharp/ElementHandle.cs index 7d6a341c1..807b16cbc 100644 --- a/lib/PuppeteerSharp/ElementHandle.cs +++ b/lib/PuppeteerSharp/ElementHandle.cs @@ -277,22 +277,6 @@ public async Task QuerySelectorAllHandleAsync(string selector) return elements; } - /// - public Task XPathAsync(string expression) - { - if (expression is null) - { - throw new ArgumentNullException(nameof(expression)); - } - - if (expression.StartsWith("//", StringComparison.Ordinal)) - { - expression = $".{expression}"; - } - - return BindIsolatedHandleAsync(handle => handle.QuerySelectorAllAsync($"xpath/{expression}")); - } - /// public Task BoundingBoxAsync() => BindIsolatedHandleAsync(async handle => diff --git a/lib/PuppeteerSharp/Frame.cs b/lib/PuppeteerSharp/Frame.cs index 74f34b724..4eddcdbee 100644 --- a/lib/PuppeteerSharp/Frame.cs +++ b/lib/PuppeteerSharp/Frame.cs @@ -119,22 +119,6 @@ public async Task WaitForSelectorAsync(string selector, WaitForS return await queryHandler.WaitForAsync(this, null, updatedSelector, options).ConfigureAwait(false); } - /// - public Task WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null) - { - if (string.IsNullOrEmpty(xpath)) - { - throw new ArgumentNullException(nameof(xpath)); - } - - if (xpath.StartsWith("//", StringComparison.OrdinalIgnoreCase)) - { - xpath = $".{xpath}"; - } - - return WaitForSelectorAsync($"xpath/{xpath}", options); - } - /// public Task WaitForFunctionAsync(string script, WaitForFunctionOptions options, params object[] args) { @@ -191,13 +175,6 @@ public async Task QuerySelectorAllAsync(string selector) return await document.QuerySelectorAllAsync(selector).ConfigureAwait(false); } - /// - public async Task XPathAsync(string expression) - { - var document = await GetDocumentAsync().ConfigureAwait(false); - return await document.XPathAsync(expression).ConfigureAwait(false); - } - /// public Task WaitForDevicePromptAsync(WaitForOptions options = default) => GetDeviceRequestPromptManager().WaitForDevicePromptAsync(options); diff --git a/lib/PuppeteerSharp/IElementHandle.cs b/lib/PuppeteerSharp/IElementHandle.cs index b69f9cf52..c1d8d871a 100644 --- a/lib/PuppeteerSharp/IElementHandle.cs +++ b/lib/PuppeteerSharp/IElementHandle.cs @@ -293,14 +293,6 @@ public interface IElementHandle : IJSHandle /// Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM. Task WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null); - /// - /// Evaluates the XPath expression relative to the elementHandle. If there's no such element, the method will resolve to null. - /// - /// Expression to evaluate . - /// Task which resolves to an array of . - [Obsolete("Use " + nameof(QuerySelectorAsync) + " instead")] - Task XPathAsync(string expression); - /// /// Checks if an element is visible using the same mechanism as . /// diff --git a/lib/PuppeteerSharp/IFrame.cs b/lib/PuppeteerSharp/IFrame.cs index b3ebbd505..bb1a0743c 100644 --- a/lib/PuppeteerSharp/IFrame.cs +++ b/lib/PuppeteerSharp/IFrame.cs @@ -389,44 +389,6 @@ public interface IFrame /// If timeout occurred. Task WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null); - /// - /// Waits for a selector to be added to the DOM. - /// - /// A xpath selector of an element to wait for. - /// Optional waiting parameters. - /// 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. - /// - /// - /// 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(); - /// ]]> - /// - /// - /// - /// If timeout occurred. - [Obsolete("Use " + nameof(WaitForSelectorAsync) + " instead")] - Task WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null); - - /// - /// Evaluates the XPath expression. - /// - /// Expression to evaluate . - /// Task which resolves to an array of . - [Obsolete("Use " + nameof(QuerySelectorAsync) + " instead")] - Task XPathAsync(string expression); - /// /// This method is typically coupled with an action that triggers a device /// request from an api such as WebBluetooth. diff --git a/lib/PuppeteerSharp/IPage.cs b/lib/PuppeteerSharp/IPage.cs index 57d6391c0..8360c8d01 100644 --- a/lib/PuppeteerSharp/IPage.cs +++ b/lib/PuppeteerSharp/IPage.cs @@ -1393,46 +1393,6 @@ public interface IPage : IDisposable, IAsyncDisposable /// Task WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null); - /// - /// Waits for a xpath selector to be added to the DOM. - /// - /// A xpath selector of an element to wait for. - /// Optional waiting parameters. - /// 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. - /// - /// - /// 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(); - /// ]]> - /// - /// - /// - [Obsolete("Use " + nameof(WaitForSelectorAsync) + " instead")] - Task WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null); - - /// - /// Evaluates the XPath expression. - /// - /// Expression to evaluate . - /// Task which resolves to an array of . - /// - /// Shortcut for page.MainFrame.XPathAsync(expression). - /// - [Obsolete("Use " + nameof(QuerySelectorAsync) + " instead")] - Task XPathAsync(string expression); - /// /// This method is typically coupled with an action that triggers a device /// request from an api such as WebBluetooth. diff --git a/lib/PuppeteerSharp/Page.cs b/lib/PuppeteerSharp/Page.cs index ba0034987..006229157 100644 --- a/lib/PuppeteerSharp/Page.cs +++ b/lib/PuppeteerSharp/Page.cs @@ -255,11 +255,6 @@ public Task QuerySelectorAllHandleAsync(string selector) => MainFrame.QuerySelectorAllHandleAsync(selector); /// -#pragma warning disable CS0618 // Using obsolete - public Task XPathAsync(string expression) => MainFrame.XPathAsync(expression); -#pragma warning restore CS0618 - - /// public Task WaitForDevicePromptAsync( WaitForOptions options = default(WaitForOptions)) => MainFrame.WaitForDevicePromptAsync(options); @@ -676,12 +671,6 @@ public Task WaitForSelectorAsync(string selector, WaitForSelecto => MainFrame.WaitForSelectorAsync(selector, options ?? new WaitForSelectorOptions()); /// -#pragma warning disable CS0618 // WaitForXPathAsync is obsolete - public Task WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null) - => MainFrame.WaitForXPathAsync(xpath, options ?? new WaitForSelectorOptions()); -#pragma warning restore CS0618 - - /// public Task WaitForNavigationAsync(NavigationOptions options = null) => MainFrame.WaitForNavigationAsync(options);