Skip to content

Selenium: add WebDriver BiDi extension methods #183

Open
@radmorecameron

Description

@radmorecameron

Which package is this feature for?

  • Deque.AxeCore.Selenium

Feature description

Version v4.25.0 of Selenium added some support for WebDriver BiDi (https://w3c.github.io/webdriver-bidi/) this should make it possible to execute javascript asyncronously. I think it'd be good to add extensions for the BrowsingContext to run axe against the page if possible.

BiDi information:

  • WebDriverOptions (ex: ChromeOptions) need to have UseWebSocketUrl enabled in order to use BiDi
  • to get a bidi driver use AsBiDiContextAsync on a WebDriver object.

Here is an example of some code using BiDi to get the title of the page asyncronously:

using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;

namespace BidiExample;

public class BidiTest
{
    public async Task MyMethod()
    {
        var options = new ChromeOptions
        {
            UseWebSocketUrl = true
        };
        var driver = new ChromeDriver(options);
        var biDiContext = await driver.AsBiDiContextAsync();
        var title = await biDiContext.GetPageTitleAsync();
        Assert.NotNull(title);
    }

    // Here is some example code on how to execute a script and return the value using the BrowsingContext from BiDi:
    public static async Task<string> GetPageTitleAsync(this BrowsingContext bidiContext)
    {
        return (await bidiContext.Script.EvaluateAsync<StringRemoteValue>("document.title", true)).Value;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions