### Quick Start Example with ChromeDriver Source: https://github.com/seleniumhq/selenium/blob/trunk/java/README.md A basic Java example demonstrating how to launch Chrome, navigate to a URL, print the title, and close the browser using Selenium WebDriver. Requires ChromeDriver to be installed or managed by Selenium Manager. ```java import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Example { public static void main(String[] args) { WebDriver driver = new ChromeDriver(); try { driver.get("https://www.selenium.dev"); System.out.println(driver.getTitle()); } finally { driver.quit(); } } } ``` -------------------------------- ### Quick Start with ChromeDriver Source: https://github.com/seleniumhq/selenium/blob/trunk/dotnet/src/webdriver/assets/nuget/README.md A basic C# example demonstrating how to initialize a ChromeDriver, navigate to a URL, and print the page title. Selenium Manager automatically handles driver installation. ```csharp using System; using OpenQA.Selenium.Chrome; using var driver = new ChromeDriver(); driver.Url = "https://www.selenium.dev"; Console.WriteLine(driver.Title); ``` -------------------------------- ### Quick Start: Automate Browser with Selenium WebDriver Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/selenium-webdriver/README.md A basic example demonstrating how to launch a browser, navigate to a URL, get the page title, and close the browser using selenium-webdriver. Selenium Manager handles driver installation automatically. ```javascript const { Builder, Browser } = require('selenium-webdriver') ;(async function example() { let driver = await new Builder().forBrowser(Browser.CHROME).build() try { await driver.get('https://www.selenium.dev') console.log(await driver.getTitle()) } finally { await driver.quit() } })() ``` -------------------------------- ### Start Local Selenium Grid Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Start a local Selenium Grid instance using the command line. Requires Java to be installed. ```bash selenium-manager --grid ``` ```bash java -jar selenium-server.jar standalone ``` -------------------------------- ### Java Selenium Setup and Example Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/skills.md Demonstrates how to set up the Selenium Java dependency using Maven and provides a basic example of initializing a ChromeDriver, navigating to a URL, and printing the page title. ```xml org.seleniumhq.selenium selenium-java 4.x.x ``` ```java import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class SeleniumTest { public static void main(String[] args) { ChromeOptions options = new ChromeOptions(); WebDriver driver = new ChromeDriver(options); try { driver.get("https://www.selenium.dev/"); System.out.println("Title: " + driver.getTitle()); } finally { driver.quit(); } } } ``` -------------------------------- ### Quick Start: Automate Browser with Ruby Source: https://github.com/seleniumhq/selenium/blob/trunk/rb/README.md A basic example demonstrating how to initialize a Chrome WebDriver instance, navigate to a URL, print the page title, and ensure the browser is closed. Selenium Manager automatically handles driver installation. ```ruby require "selenium-webdriver" driver = Selenium::WebDriver.for :chrome begin driver.get "https://www.selenium.dev" puts driver.title ensure driver.quit end ``` -------------------------------- ### Configure Selenium via Command Line Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/config.txt Demonstrates how to start the Selenium standalone server using command line flags for classpath extensions and configuration files. ```bash java -jar selenium.jar --ext $ADDITIONAL_CLASSPATH standalone java -jar selenium.jar standalone --config myconfig.toml java -jar selenium.jar standalone --config-help ``` -------------------------------- ### Ruby Selenium Example Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/skills.md Explains how to install the selenium-webdriver gem and presents a Ruby example for initializing a Chrome driver, navigating to a URL, and printing the page title. ```ruby require 'selenium-webdriver' driver = Selenium::WebDriver.for :chrome begin driver.navigate.to "https://www.selenium.dev/" puts "Title: #{driver.title}" ensure driver.quit end ``` -------------------------------- ### Python Selenium Example Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/skills.md Provides instructions for installing the Selenium Python package and includes an example of initializing a Chrome driver, navigating to a URL, and printing the page title. ```python from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() driver = webdriver.Chrome(options=options) try: driver.get("https://www.selenium.dev/") print("Title:", driver.title) finally: driver.quit() ``` -------------------------------- ### JavaScript (Node.js) Selenium Example Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/skills.md Shows how to install the selenium-webdriver package for Node.js and provides an example of initializing a Chrome driver, navigating to a URL, and logging the page title. ```javascript const {Builder} = require('selenium-webdriver'); (async function example() { let driver = await new Builder().forBrowser('chrome').build(); try { await driver.get('https://www.selenium.dev/'); console.log('Title:', await driver.getTitle()); } finally { await driver.quit(); } })(); ``` -------------------------------- ### Run Local Tests: Start Webserver with Bazel Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/readme.txt This command starts the local test webserver using Bazel. It's essential for running integration tests. The command specifies the target '//java/test/org/openqa/selenium/environment:appserver'. Once running, the server is accessible at http://localhost:2310/javascript. ```bash bazel run //java/test/org/openqa/selenium/environment:appserver ``` -------------------------------- ### Install Selenium Java Locally Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Use this command to build and install Selenium Java components into your local Maven repository. ```shell ./go java:install ``` -------------------------------- ### Start Distributor with TOML Config Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Launches the Distributor using a TOML configuration file. ```bash java -jar selenium.jar distributor --config grid.toml ``` -------------------------------- ### Start Dedicated Local Distributor Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Starts a dedicated Distributor server using the default in-memory backend. ```bash java -jar selenium.jar distributor \ --port 5553 \ --sessions http://localhost:5556 \ --session-queue http://localhost:5559 ``` -------------------------------- ### Install Python Package Locally Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Build and install the Selenium Python package (wheel) locally. Consider using a virtual environment to avoid permission issues. ```shell ./go py:install ``` -------------------------------- ### Start RedisBackedSessionMap Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/sessionmaps.txt Use this command to start the Redis-backed session map. Ensure Redis is running and accessible at the specified host and port. ```bash java -jar selenium.jar sessions \ --sessions-implementation org.openqa.selenium.grid.sessionmap.redis.RedisBackedSessionMap \ --sessions-scheme redis \ --sessions-host "" \ --sessions-port ``` -------------------------------- ### Start Standalone Grid Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Launches a Selenium Grid in standalone mode, embedding the Distributor. ```bash java -jar selenium.jar standalone ``` -------------------------------- ### Install selenium-webdriver Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/selenium-webdriver/README.md Install the selenium-webdriver package using npm. Requires Node.js version 20 or higher. ```bash npm install selenium-webdriver ``` -------------------------------- ### Install Selenium WebDriver via npm Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/selenium-webdriver/CHANGES.md Use npm to install the Selenium WebDriver JavaScript bindings. This is the initial release command for npm. ```bash npm install selenium-webdriver ``` -------------------------------- ### Start Selenium Grid with Python Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Connect to a Selenium Grid instance using Python. Ensure the Selenium Grid is running on the specified host and port. ```python from selenium import webdriver driver = webdriver.Remote( command_executor="http://localhost:4444", options=webdriver.ChromeOptions() ) ``` -------------------------------- ### Start RedisBackedDistributor Replica 1 Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Starts the first replica of a Redis-backed Distributor. Ensure Redis is running and accessible. ```bash # Replica 1 java -jar selenium.jar distributor \ --port 5553 \ --distributor-implementation org.openqa.selenium.grid.distributor.redis.RedisBackedDistributor \ --distributor-backend-url redis://redis-host:6379 \ --sessions http://localhost:5556 \ --session-queue http://localhost:5559 ``` -------------------------------- ### .NET (C#) Selenium Example Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/skills.md Details how to add the Selenium.WebDriver NuGet package and provides a C# example for initializing a ChromeDriver, navigating to a URL, and printing the page title. ```csharp using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using (IWebDriver driver = new ChromeDriver()) { driver.Navigate().GoToUrl("https://www.selenium.dev/"); Console.WriteLine("Title: " + driver.Title); } ``` -------------------------------- ### Java Logging Example Source: https://github.com/seleniumhq/selenium/blob/trunk/java/AGENTS.md Demonstrates how to use Java's built-in logging utility. Import java.util.logging.Logger to use this. ```java import java.util.logging.Logger; private static final Logger LOG = Logger.getLogger(MyClass.class.getName()); LOG.warning("actionable: something needs attention"); LOG.info("useful: server started on port 4444"); LOG.fine("diagnostic: request details for debugging"); ``` -------------------------------- ### Install selenium-webdriver Gem Source: https://github.com/seleniumhq/selenium/blob/trunk/rb/README.md Install the selenium-webdriver gem using the gem command. This is the first step to using Selenium in your Ruby projects. ```bash gem install selenium-webdriver ``` -------------------------------- ### Start RedisBackedDistributor Replica 2 Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Starts a second replica of a Redis-backed Distributor. This replica should use a different port or host if running on the same machine. ```bash # Replica 2 (same flags, different --port or different host) java -jar selenium.jar distributor \ --port 5554 \ --distributor-implementation org.openqa.selenium.grid.distributor.redis.RedisBackedDistributor \ --distributor-backend-url redis://redis-host:6379 \ --sessions http://localhost:5556 \ --session-queue http://localhost:5559 ``` -------------------------------- ### Start JdbcBackedSessionMap Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/sessionmaps.txt Start the JDBC-backed session map by providing the implementation class, scheme, and JDBC connection details. Ensure the JDBC driver JAR is available. ```bash SESSIONS_IMPLEMENTATION=org.openqa.selenium.grid.sessionmap.jdbc.JdbcBackedSessionMap \ SESSIONS_SCHEME=jdbc \ java -jar selenium.jar --ext $(coursier fetch -p org.seleniumhq.selenium:selenium-session-map-jdbc:latest.release org.postgresql:postgresql:latest.release) \ sessions \ --jdbc-user "" --jdbc-password "" \ --jdbc-url "" ``` -------------------------------- ### Define Selenium Configuration in TOML Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/config.txt An example of a TOML configuration file structure for Selenium, defining server and node settings such as port, host, and session limits. ```toml [server] # Start on a different port than normal port = 4445 host = "localhost" [node] max-sessions = 12 ``` -------------------------------- ### Start Chrome Browser in .NET (C#) Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Initializes a Chrome browser instance. Selenium Manager handles the chromedriver. ```csharp using OpenQA.Selenium; using OpenQA.Selenium.Chrome; IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("https://example.com"); ``` -------------------------------- ### Start Ruby Interactive Console Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Use this command to create an interactive REPL with all Ruby gems loaded, instead of using `irb`. ```shell bazel run //rb:console ``` -------------------------------- ### Install Selenium Python Bindings Source: https://github.com/seleniumhq/selenium/blob/trunk/py/docs/source/index.md Install the latest official release of the Selenium Python bindings using pip. Consider using a virtual environment for isolation. ```bash pip install -U selenium ``` -------------------------------- ### Install Nightly Selenium Python Bindings Source: https://github.com/seleniumhq/selenium/blob/trunk/py/docs/source/index.md Install the nightly development release of the Selenium Python bindings using pip. This requires specifying an index URL. ```bash pip install -U --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ selenium ``` -------------------------------- ### Install Python Dependencies Locally Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Install Python dependencies from the lock file before running Python code locally. ```shell pip install -r py/requirements_lock.txt ``` -------------------------------- ### Start Chrome Browser in Ruby Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Initializes a Chrome browser instance. Selenium Manager handles the chromedriver. ```ruby require 'selenium-webdriver' driver = Selenium::WebDriver.for :chrome driver.navigate.to 'https://example.com' ``` -------------------------------- ### Run JavaScript Grid UI Unit Tests Source: https://github.com/seleniumhq/selenium/blob/trunk/CONTRIBUTING.md Install dependencies and run JavaScript Grid UI unit tests. Navigate to the correct directory first. ```shell % cd javascript/grid-ui && npm install && npm test ``` -------------------------------- ### Start Chrome Browser in Java Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Initializes a Chrome browser instance. Selenium Manager automatically handles the chromedriver. ```java import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; WebDriver driver = new ChromeDriver(); // Selenium Manager handles chromedriver driver.get("https://example.com"); ``` -------------------------------- ### Start Chrome Browser in Python Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Initializes a Chrome browser instance. Selenium Manager automatically handles the chromedriver. ```python from selenium import webdriver driver = webdriver.Chrome() # Selenium Manager handles chromedriver automatically driver.get("https://example.com") ``` -------------------------------- ### Java Javadoc Example Source: https://github.com/seleniumhq/selenium/blob/trunk/java/AGENTS.md Illustrates the standard Javadoc format for documenting public APIs in Java. ```java /** * Brief description. * * @param name description * @return description * @throws ExceptionType when condition */ ``` -------------------------------- ### Start Chrome Browser in JavaScript (Node.js) Source: https://github.com/seleniumhq/selenium/blob/trunk/rust/src/resources/rules.md Initializes a Chrome browser instance using the Builder pattern. Selenium Manager handles the chromedriver. ```javascript const { Builder } = require('selenium-webdriver'); const driver = await new Builder().forBrowser('chrome').build(); await driver.get('https://example.com'); ``` -------------------------------- ### Launch Chrome Browser and Navigate Source: https://github.com/seleniumhq/selenium/blob/trunk/py/docs/source/index.md Launches a new Chrome browser instance, navigates to a specified URL, and then closes the browser. This is a basic example of browser automation. ```python from selenium import webdriver driver = webdriver.Chrome() driver.get("https://selenium.dev") driver.quit() ``` -------------------------------- ### Example Error Output with Stack Traces Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/selenium-webdriver/CHANGES.md Shows the format of an error message after a task fails, including appended stack traces from when the task was scheduled. ```text Error: element not found Wait timed out after 2002ms at From: Task: element not found at From: Task: WebDriver.call(function) at ``` -------------------------------- ### Validate pip report structure in update_py_deps.py Source: https://github.com/seleniumhq/selenium/wiki/.pr_agent_accepted_suggestions Ensure the parsed pip report is a dictionary and contains the expected 'install' key with a list value before proceeding. ```python if not isinstance(report, dict): raise RuntimeError(f"Unexpected pip report format: expected dict, got {type(report).__name__}") install_list = report.get("install") if not isinstance(install_list, list): raise RuntimeError(f"Missing or invalid 'install' list in pip report") ``` -------------------------------- ### BiDi UseTransport Ignores CancellationToken Source: https://github.com/seleniumhq/selenium/wiki/.pr_agent_accepted_suggestions This C# code snippet highlights an issue where `BiDiOptionsBuilder.UseTransport(ITransport transport)` ignores the provided `CancellationToken`. This prevents cancellation during connection setup when using an injected transport, contrary to the default WebSocket behavior. ```csharp BiDiOptionsBuilder.UseTransport(ITransport transport) ``` -------------------------------- ### Run Selenium Tests with Tox (Specific Environment) Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings Executes Selenium tests using Tox for a specific Python version and browser driver combination. This example runs tests for Python 2.7 with the Marionette driver. ```bash tox -e py27-marionette ``` -------------------------------- ### Load Custom Distributor via Extension Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Starts the Distributor, loading a custom implementation from a JAR file. The custom implementation must extend org.openqa.selenium.grid.distributor.Distributor and have a static create(Config) factory method. ```bash java -jar selenium.jar \ --ext /path/to/my-distributor.jar \ distributor \ --distributor-implementation com.example.MyDistributor \ --distributor-backend-url mydb://host:port/grid ``` -------------------------------- ### Demonstrating Nested Loadable Components in Java Test Source: https://github.com/seleniumhq/selenium/wiki/LoadableComponent A JUnit test class demonstrating the setup and usage of nested LoadableComponents. It initializes ProjectPage, SecuredPage, and EditIssue components and then calls their methods to interact with the web page. This example assumes the use of FirefoxDriver. ```java public class FooTest { private EditIssue editIssue; @Before public void prepareComponents() { WebDriver driver = new FirefoxDriver(); ProjectPage project = new ProjectPage(driver, "selenium"); SecuredPage securedPage = new SecuredPage(driver, project, "example", "top secret"); editIssue = new EditIssue(driver, securedPage); } @Test public void demonstrateNestedLoadableComponents() { editIssue.get(); editIssue.setSummary("Summary"); editIssue.enterDescription("This is an example"); } } ``` -------------------------------- ### Prepare Release Updates Source: https://github.com/seleniumhq/selenium/wiki/Releasing-Selenium Run this command to prepare for a release by updating versions and tags. Use 'selenium-X.Y.0' for full releases and 'selenium-X.Y.Z-language' for patch releases. ```bash ./go release_updates ``` -------------------------------- ### Mark Test Expected to Fail with Conditions (Python) Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings This example shows how to mark a test as expected to fail based on specific conditions, such as running on a particular platform (macOS) and with a specific driver (Firefox). It includes a reason for the failure and the expected exception type. ```python import sys import pytest from selenium.common.exceptions import WebDriverException @pytest.mark.xfail_firefox( condition=sys.platform == 'darwin', reason='https://myissuetracker.com/issue?id=1234', raises=WebDriverException def test_something(driver): assert something is True ``` -------------------------------- ### Install Selenium with Pip Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings Installs the latest official release of the Selenium Python package using pip. It is recommended to install packages within a virtual environment. ```bash pip install selenium ``` -------------------------------- ### Install Unreleased Selenium Version from Source Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings Installs the latest unreleased version of Selenium from its GitHub repository. This involves cloning the repository, preparing the Python package, and installing it. ```bash git clone https://github.com/SeleniumHQ/selenium cd selenium ./go py_prep_for_install_release cd py python setup.py install ``` -------------------------------- ### Generate API Documentation Source: https://github.com/seleniumhq/selenium/wiki/Releasing-Selenium Generate API documentation for all components. ```bash ./go all:docs ``` -------------------------------- ### Logging in Python Source: https://github.com/seleniumhq/selenium/blob/trunk/py/AGENTS.md Demonstrates how to set up and use Python's logging module for different levels of messages. ```python logger = logging.getLogger(__name__) logger.warning("actionable: something needs attention") logger.info("useful: driver started successfully") logger.debug("diagnostic: request payload for debugging") ``` -------------------------------- ### Build and Test with Go Script (Ruby/Python) Source: https://github.com/seleniumhq/selenium/wiki/Build-Instructions This command uses the 'go' script in the project root to build and test the project, primarily for Ruby and Python. It compiles the source code and runs necessary tests. For Unix-like systems, the executable permission might be needed. ```bash cd $WEBDRIVER_HOME go ``` ```bash # or, on a UNIX system: ./go ``` -------------------------------- ### Build Python Docs with Tox Source: https://github.com/seleniumhq/selenium/blob/trunk/py/docs/README.rst This command sequence sets up a virtual environment, installs tox, clones the Selenium repository, and then runs tox to build the Python documentation. It's a streamlined process for generating documentation without a full Bazel build. ```console python3 -m venv venv source venv/bin/activate pip install tox git clone git@github.com:SeleniumHQ/selenium.git cd selenium/ # uncomment and switch to your development branch if needed #git switch -c feature-branch origin/feature-branch tox -c py/tox.ini -e docs ``` -------------------------------- ### Example ControlFlow Warning Output Source: https://github.com/seleniumhq/selenium/wiki/WebDriverJs An example of the warning message generated in the console when an unchained task is detected by the Selenium promise manager. ```shell [2017-03-06T02:18:14Z] [WARNING] [promise.ControlFlow] Detected scheduling of an unchained task. When the promise manager is disabled, unchained tasks will not wait for previously scheduled tasks to finish before starting to execute. New task: Task: WebDriver.navigate().to(http://www.google.com/ncr) at thenableWebDriverProxy.schedule (/Users/jleyba/Development/test/node_modules/selenium-webdriver/lib/webdriver.js:816:17) at Navigation.to (/Users/jleyba/Development/test/node_modules/selenium-webdriver/lib/webdriver.js:1140:25) at thenableWebDriverProxy.get (/Users/jleyba/Development/test/node_modules/selenium-webdriver/lib/webdriver.js:997:28) at Object. (/Users/jleyba/Development/test/log.js:10:8) Previous task: Task: WebDriver.createSession() at Function.createSession (/Users/jleyba/Development/test/node_modules/selenium-webdriver/lib/webdriver.js:777:24) ``` -------------------------------- ### Initialize Chrome WebDriver in Python Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings Initializes a Chrome WebDriver instance in Python. This requires the Selenium library to be installed and the ChromeDriver executable to be in the system's PATH or specified explicitly. ```python from selenium import webdriver driver = webdriver.Chrome() ``` -------------------------------- ### Initialize Firefox WebDriver in Python Source: https://github.com/seleniumhq/selenium/wiki/Python-Bindings Initializes a Firefox WebDriver instance in Python. This requires the Selenium library to be installed and the GeckoDriver executable to be in the system's PATH or specified explicitly. ```python from selenium import webdriver driver = webdriver.Firefox() ``` -------------------------------- ### Publish All Components Source: https://github.com/seleniumhq/selenium/wiki/Releasing-Selenium Execute this command to publish all Selenium components after versioning and tagging are complete. ```bash ./go all:release ``` -------------------------------- ### Start Selenium Debug Server Source: https://github.com/seleniumhq/selenium/wiki/Automation-Atoms Starts the local debug server to facilitate the testing of browser atoms. This allows developers to refresh the browser to see changes in real-time without recompiling, provided no dependency changes occur. ```shell ./go debug-server & ``` -------------------------------- ### Simplified @FindBy Annotation for Element Location Source: https://github.com/seleniumhq/selenium/wiki/PageFactory This example shows a more concise way to use the @FindBy annotation by directly specifying the 'name' attribute. This reduces verbosity while maintaining the same functionality as the previous examples. The rest of the class remains unchanged. ```java public class GoogleSearchPage { @FindBy(name = "q") private WebElement searchBox; // The rest of the class is unchanged. } ``` -------------------------------- ### Start Selenium Hub with HTTPS Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/security.txt Starts the Selenium Hub in HTTPS mode by providing paths to the private key and certificate files. This is essential for securing communication when the server is exposed to the internet or handles sensitive data. ```bash java -jar selenium.jar \ hub \ --https-private-key /path/to/key.pkcs8 \ --https-certificate /path/to/cert.pem ``` -------------------------------- ### Configure and Launch Multiple FirefoxDriver Sessions Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/selenium-webdriver/CHANGES.md Demonstrates how to use a single firefox.Binary instance to configure and launch multiple FirefoxDriver sessions. This is useful for managing multiple browser instances efficiently. ```javascript var binary = new firefox.Binary(); var options = new firefox.Options().setBinary(binary); var builder = new Builder().setFirefoxOptions(options); var driver1 = builder.build(); var driver2 = builder.build(); ``` -------------------------------- ### Start Selenium Node with Kubernetes Extension (Image Mode) Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/kubernetes.txt This command starts a Selenium Grid Node using the Kubernetes extension in image mode. It specifies the extension JAR and configures two browser images (Chrome and Firefox) with their respective capabilities. ```bash java -jar selenium.jar \ --ext $(coursier fetch -p org.seleniumhq.selenium:selenium-node-kubernetes:latest.release) \ node \ -K selenium/standalone-chrome:latest '{"browserName": "chrome"}' \ -K selenium/standalone-firefox:latest '{"browserName": "firefox"}' ``` -------------------------------- ### Get 'value' Attribute from Input Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/atoms/test/attribute_typescript_test.html Retrieves the 'value' attribute from an input element. ```javascript assertAttributeEquals(assert, 'unchecky', byId('unchecky'), 'value'); ``` -------------------------------- ### Start Selenium Node with Kubernetes Extension (Template Mode) Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/kubernetes.txt This command starts a Selenium Grid Node using the Kubernetes extension in template mode. It references a Kubernetes ConfigMap named 'my-chrome-template' which contains a full Job YAML definition for launching browser sessions. ```bash java -jar selenium.jar \ --ext $(coursier fetch -p org.seleniumhq.selenium:selenium-node-kubernetes:latest.release) \ node \ -K configmap:my-chrome-template '{"browserName": "chrome"}' ``` -------------------------------- ### Initialize and Use ILogger in C# Source: https://github.com/seleniumhq/selenium/blob/trunk/dotnet/AGENTS.md Demonstrates how to get an instance of ILogger for a class and log messages at different levels (Warn, Info, Debug). Ensure the OpenQA.Selenium.Internal.Logging namespace is imported. ```csharp using OpenQA.Selenium.Internal.Logging; private static readonly ILogger _logger = Log.GetLogger(); _logger.Warn("actionable: something needs attention"); _logger.Info("useful: driver started successfully"); _logger.Debug("diagnostic: request details for debugging"); ``` -------------------------------- ### Build all components for a language Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Use this command to build all components for a specific language. Replace with the desired language. ```shell bazel build ///... ``` -------------------------------- ### Java Deprecated Method Example Source: https://github.com/seleniumhq/selenium/blob/trunk/java/AGENTS.md Shows how to mark a method as deprecated and indicate it will be removed in the future. ```java @Deprecated(forRemoval = true) public void legacyMethod() { } ``` -------------------------------- ### Configure Bazel Output Directory (Windows) Source: https://github.com/seleniumhq/selenium/blob/trunk/README.md Set the Bazel output directory to `C:/tmp` to avoid issues with long file paths. Create the `.bazelrc.windows.local` file in the project root and add the specified line. ```bazelrc startup --output_user_root=C:/tmp ``` -------------------------------- ### Initialize WebDriver and Perform Basic Navigation Source: https://github.com/seleniumhq/selenium/wiki/Ruby-Bindings Demonstrates how to initialize a Firefox WebDriver instance, navigate to a URL, interact with elements by name, and terminate the session. ```ruby require "selenium-webdriver" driver = Selenium::WebDriver.for :firefox driver.navigate.to "http://google.com" element = driver.find_element(name: 'q') element.send_keys "Hello WebDriver!" element.submit puts driver.title driver.quit ``` -------------------------------- ### RedisBackedDistributor Configuration TOML Source: https://github.com/seleniumhq/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/distributor.txt Example TOML configuration for RedisBackedDistributor. This can be used with the --config flag. ```toml [distributor] implementation = "org.openqa.selenium.grid.distributor.redis.RedisBackedDistributor" backend-url = "redis://redis-host:6379" ``` -------------------------------- ### Get Unknown/Expando Attribute Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/atoms/test/attribute_typescript_test.html Retrieves the value of an unknown or expando attribute using the getAttribute fallback mechanism. ```javascript assertAttributeEquals(assert, 'lovely', byId('cheddar'), 'unknown'); ``` -------------------------------- ### Initialize and Test Web SQL Database Operations Source: https://github.com/seleniumhq/selenium/blob/trunk/javascript/atoms/test/html5/database_test.html This snippet initializes a Web SQL database using the Closure Library and performs a series of QUnit tests. It covers opening databases with specific versions, executing SQL queries, and handling invalid SQL statements. ```JavaScript var createdDatabase = new goog.Promise(function(success, failure) { if (DATABASE_NOT_WORKING) { success(); return; } try { var win = bot.getWindow(); var db = win.openDatabase('testDB', '1.0', 'db name', 2 * 1024 * 1024); db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS docids (id INTEGER PRIMARY KEY, name TEXT, owner TEXT)'); tx.executeSql('INSERT OR REPLACE INTO docids VALUES (11, "aa", "Manager")'); }, failure, success); } catch (e) { failure(e); } }); QUnit.test('openDatabaseWithSameVersion', function(assert) { var done = assert.async(); createdDatabase.then(function() { var db = bot.storage.database.openOrCreate('testDB', '1.0'); assert.ok(db !== null); assert.strictEqual(db.version, '1.0'); done(); }); }); QUnit.test('executeSqlWithValidArgument', function(assert) { var done = assert.async(); createdDatabase.then(function() { return new goog.Promise(function(success, failure) { bot.storage.database.executeSql('testDB', 'SELECT id from docids WHERE owner = ? AND name = ?', ['Eng-A', 'aabb'], function(tx, result) { success(result); }, goog.partial(failure, 'Transaction failed'), goog.nullFunction); }).then(function(result) { assert.strictEqual(result.rows.length, 2); done(); }); }); }); ``` -------------------------------- ### Verify Release Source: https://github.com/seleniumhq/selenium/wiki/Releasing-Selenium Run this command to verify that the release artifacts have been published correctly. ```bash ./go all:verify ```