### Install Selenium2Library Source: https://context7.com/robotframework/selenium2library/llms.txt Install or upgrade to the latest version of Selenium2Library using pip. Use '==1.8.0' to install a legacy standalone version. ```bash pip install --upgrade robotframework-selenium2library ``` ```bash pip install robotframework-selenium2library==1.8.0 ``` -------------------------------- ### Explicit Default Locator Strategy Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Examples showing how to explicitly use the default locator strategy when the locator might otherwise be misinterpreted. This is useful when a locator string starts with a recognized prefix. ```robotframework Click Element name:foo Click Element default:name:foo Click Element //foo Click Element default: //foo ``` -------------------------------- ### Default Locator Strategy Examples Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Examples demonstrating the default locator strategy for various keywords. The strategy matches based on 'id' or 'name' attributes by default. ```robotframework Click Element example Click Link example Click Button example ``` -------------------------------- ### Explicit Locator Strategy Examples Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Examples of using explicit locator strategies with prefixes like 'id:', 'name:', or 'identifier:'. The 'strategy:value' syntax is preferred over 'strategy=value'. ```robotframework id:example name:example identifier:example ``` -------------------------------- ### List Windows Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deprecated. Use Get Window Handles instead. ```APIDOC ## List Windows ### Description Deprecated. Use `Get Window Handles` instead. ### Arguments None ``` -------------------------------- ### Get Element Size Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the width and height of an element identified by a locator. Both dimensions are returned as integers. ```RobotFramework ${width} ${height} = Get Element Size css:div#container ``` -------------------------------- ### Navigate Between Pages Example Source: https://context7.com/robotframework/selenium2library/llms.txt Demonstrates navigating to different URLs using Go To, Go Back, and Reload Page, with location verification. ```robotframework *** Test Cases *** Navigate Through Pages Open Browser https://example.com Chrome Go To https://example.com/page1 Location Should Be https://example.com/page1 Go Back Location Should Be https://example.com Reload Page Close Browser ``` -------------------------------- ### Locator Strategies Example Source: https://context7.com/robotframework/selenium2library/llms.txt Shows how to locate and interact with elements using various strategies like id, CSS, XPath, link text, and tag. ```robotframework *** Test Cases *** Locator Strategies Open Browser https://example.com Chrome # By id Click Element id=submit-button # By CSS Click Element css=input[type='text'] # By XPath Click Element xpath=//button[@data-action='save'] # By link text Click Link More information... Close Browser ``` -------------------------------- ### Open and Close Browser Example Source: https://context7.com/robotframework/selenium2library/llms.txt Launches a new browser session using Open Browser and tears it down cleanly with Close Browser. Includes a basic title verification. ```robotframework *** Test Cases *** Open And Close Browser Open Browser ${BASE_URL} ${BROWSER} Title Should Be Example Domain Close Browser *** Keywords *** Teardown All Sessions Close All Browsers ``` -------------------------------- ### Capture Page Screenshot Examples Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Shows how to capture screenshots with different naming conventions, including automatic indexing and custom formats. ```Robot Framework Capture Page Screenshot ``` ```Robot Framework Capture Page Screenshot custom_name.png ``` ```Robot Framework Capture Page Screenshot custom_with_index_{index}.png ``` ```Robot Framework Capture Page Screenshot formatted_index_{index:03}.png ``` -------------------------------- ### Locator Strategy Examples for Click Element Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Illustrates how to use different locator strategies with the 'Click Element' keyword. Using IDs is recommended for simplicity and speed when possible. ```robotframework Click Element id:foo ``` ```robotframework Click Element css:div#foo h1 ``` ```robotframework Click Element xpath: //div[@id="foo"]//h1 ``` ```robotframework Click Element xpath: //* [contains(text(), "example")] ``` -------------------------------- ### Interacting with Forms Example Source: https://context7.com/robotframework/selenium2library/llms.txt Demonstrates common form interactions including inputting text, selecting checkboxes, and submitting forms. ```robotframework *** Test Cases *** Fill And Submit Login Form Open Browser https://example.com/login Chrome Input Text id=username testuser Input Password id=password secret123 Select Checkbox id=remember-me Click Button Log In Wait Until Page Contains Welcome, testuser Close Browser ``` -------------------------------- ### Get List Items Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves all labels or values from a selection list. By default, it returns visible labels. Set the 'values' argument to True to get the underlying values. Support for returning values is new in Selenium2Library 3.0. ```RobotFramework ${labels} = Get List Items mylist ${values} = Get List Items css:#example select values=True ``` -------------------------------- ### Assertions and Verification Keywords Example Source: https://context7.com/robotframework/selenium2library/llms.txt Verifies page state using keywords like Title Should Be, Page Should Contain, and Element Should Be Visible. ```robotframework *** Test Cases *** Verify Page State Open Browser https://example.com Chrome Title Should Be Example Domain Page Should Contain This domain is for use in illustrative examples Page Should Contain Element css=h1 Element Text Should Be css=h1 Example Domain Element Should Be Visible css=a Close Browser ``` -------------------------------- ### Open Browser with Different Configurations Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Opens a new browser instance to the given URL. Examples show opening with Chrome, Firefox, and Edge, including options for aliasing and remote WebDriver. ```robotframework Open Browser hhttp://example.com Chrome ``` ```robotframework Open Browser hhttp://example.com Firefox alias=Firefox ``` ```robotframework Open Browser hhttp://example.com Edge remote_url=http://127.0.0.1:4444/wd/hub ``` -------------------------------- ### Get Titles Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns and logs the titles of all currently open browser windows. ```APIDOC ## Get Titles ### Description Returns and logs the titles of all known browser windows. ### Method GET ### Endpoint /get_titles ``` -------------------------------- ### Get Source Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the complete HTML source of the current browser window or frame. ```APIDOC ## Get Source ### Description Returns the entire HTML source of the current page or frame. ### Arguments None ``` -------------------------------- ### Get Window Names Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns and logs the names of all known browser windows. This is useful for differentiating between multiple browser instances. ```APIDOC ## Get Window Names ### Description Returns and logs names of all known browser windows. ### Arguments None ``` -------------------------------- ### Input Text Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Types text into a specified text field. Use 'Input Password' if the text should not be logged. ```Robot Framework Input Text locator text ``` -------------------------------- ### Handling Alerts Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Provides examples for accepting or dismissing JavaScript alerts that appear during browser interaction. Ensure you are ready to handle the alert when it appears. ```robotframework Alert Should Be Present Expected alert text Accept Alert Dismiss Alert ``` -------------------------------- ### Get Window Titles Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns and logs the titles of all known browser windows. This helps in identifying windows by their titles. ```APIDOC ## Get Window Titles ### Description Returns and logs titles of all known browser windows. ### Arguments None ``` -------------------------------- ### Handle Pop-up Windows Source: https://context7.com/robotframework/selenium2library/llms.txt Manage browser pop-up windows using `Get Window Handles` and `Switch Window`. After opening a popup, you can switch to the new window using `Switch Window NEW`, perform actions, and then return to the main window with `Switch Window MAIN`. ```robotframework *** Test Cases *** Handle Popup Window Open Browser https://example.com Chrome Click Link Open Popup ${handles}= Get Window Handles Switch Window NEW Title Should Be Popup Title Close Window Switch Window MAIN ``` -------------------------------- ### Get WebElement Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves a WebElement based on a given locator strategy. ```APIDOC ## Get WebElement ### Description Retrieves a WebElement based on a given locator strategy. ### Method GET ### Endpoint /element ### Parameters #### Query Parameters - **locator** (string) - Required - The locator strategy and value (e.g., id:example, xpath://button[text()='Submit']) ### Response #### Success Response (200) - **element** (WebElement) - The found WebElement. ### Response Example { "element": "" } ``` -------------------------------- ### Assign ID to Element Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Demonstrates assigning a temporary ID to an element using a specific locator strategy. ```Robot Framework Assign Id To Element //ul[@class='example' and ./li[contains(., 'Stuff')]] my id ``` -------------------------------- ### Explicit Locator Strategies Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html These examples demonstrate the explicit syntax for various locator strategies. The 'strategy:value' format is supported in Selenium2Library 3.0 and newer. ```robotframework identifier:example ``` ```robotframework class:example ``` ```robotframework tag:div ``` ```robotframework xpath://div[@id="example"] ``` ```robotframework css:div#example ``` ```robotframework dom:document.images[5] ``` ```robotframework link:The example ``` ```robotframework partial link:he ex ``` ```robotframework sizzle:div.example ``` ```robotframework jquery:div.example ``` ```robotframework default:example ``` -------------------------------- ### Get Window Size Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the current window's width and height as integers. This is useful for responsive design testing or layout verification. ```APIDOC ## Get Window Size ### Description Returns current window width and height as integers. ### Arguments None ### Returns * Tuple: A tuple containing the width and height of the window. ``` -------------------------------- ### Get Window Handles Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns all current window handles as a list. This can be used to manage multiple browser windows or tabs. ```APIDOC ## Get Window Handles ### Description Return all current window handles as a list. ### Arguments None ### Returns * List: A list of window handles. ``` -------------------------------- ### Handle Alert Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Handles the current alert, with options to accept, dismiss, or leave it open. A timeout can be specified for alert appearance. New in Selenium2Library 3.0. ```Robot Framework Handle Alert ``` ```Robot Framework Handle Alert action=DISMISS ``` ```Robot Framework Handle Alert timeout=10 s ``` ```Robot Framework Handle Alert DISMISS 1 min ``` ```Robot Framework ${message} = Handle Alert ``` ```Robot Framework ${message} = Handle Alert LEAVE ``` -------------------------------- ### Input Password Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Types a password into a text field. Unlike 'Input Text', this keyword does not log the password at the INFO level. Be aware that passwords may still be logged at DEBUG or TRACE levels. ```Robot Framework Input Password password_field password ``` ```Robot Framework Input Password password_field ${PASSWORD} ``` -------------------------------- ### Waiting for Conditions Example Source: https://context7.com/robotframework/selenium2library/llms.txt Waits for asynchronous events like page content loading or element visibility using Wait Until Page Contains and Wait Until Element Is Visible. ```robotframework *** Test Cases *** Wait For Dynamic Content Open Browser https://example.com/dynamic Chrome Click Button Load Data Wait Until Page Contains Data loaded successfully timeout=15s Wait Until Element Is Visible id=results-table timeout=15s Wait Until Element Contains id=status-badge Ready Close Browser ``` -------------------------------- ### Get WebElements Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns a list of WebElement objects that match the specified locator. If no elements are found, an empty list is returned. ```APIDOC ## Get WebElements ### Description Returns list of WebElement objects matching the locator. ### Arguments * locator: The locator for the elements. ### Returns * List: A list of WebElement objects. ``` -------------------------------- ### Get All Links Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns a list containing the IDs of all links found on the current page. ```APIDOC ## Get All Links ### Description Returns a list containing ids of all links found in current page. If a link has no id, an empty string will be in the list instead. ### Method Get All Links ### Parameters None ### Response #### Success Response - **links** (list) - A list of strings, where each string is the ID of a link on the page. An empty string is used if a link has no ID. ``` -------------------------------- ### Get Element Size Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns width and height of element identified by `locator`. Both width and height are returned as integers. ```APIDOC ## Get Element Size ### Description Returns the width and height of an element. ### Arguments * `locator` - The locator for the element. ### Returns * A tuple containing the width and height of the element in pixels. ``` -------------------------------- ### Verify Checkbox Selected Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Verifies if a checkbox identified by a locator is currently selected. ```Robot Framework Checkbox Should Be Selected my_checkbox_locator ``` -------------------------------- ### Get Window Identifiers Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns and logs the ID attributes of all known browser windows. This helps in identifying specific windows. ```APIDOC ## Get Window Identifiers ### Description Returns and logs id attributes of all known browser windows. ### Arguments None ``` -------------------------------- ### Get WebElement Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the first WebElement that matches the given locator. This provides direct access to the underlying Selenium WebElement object. ```APIDOC ## Get WebElement ### Description Returns the first WebElement matching the given locator. ### Arguments * locator: The locator for the element. ``` -------------------------------- ### Select From List By Index Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Selects options from a selection list by their indexes. Indexes start from 0. For multi-selection lists, all specified options are selected. ```APIDOC ## Select From List By Index ### Description Selects options from selection list Indexes of list options start from 0. If more than one option is given for a single-selection list, the last value will be selected. With multi-selection lists all specified options are selected, but possible old selections are not cleared. See the Locating elements section for details about the locator syntax. ### Arguments * `locator` * `*indexes` ``` -------------------------------- ### Implicit XPath Strategy Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html When a locator starts with '//' or '(//', it is automatically treated as an XPath expression. This simplifies usage for XPath locators. ```robotframework Click Element //div[@id="foo"]//h1 ``` ```robotframework Click Element (//div)[2] ``` -------------------------------- ### Get Horizontal Position Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the horizontal position of an element in pixels from the left side of the page. See also 'Get Vertical Position'. ```RobotFramework Get Horizontal Position locator=my_element ``` -------------------------------- ### Opening a Browser with Selenium2Library Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Demonstrates how to open a new browser instance to a specified URL. Ensure the WebDriver is correctly configured and accessible in your system's PATH. ```robotframework *** Settings *** Library Selenium2Library *** Test Cases *** Open Browser To Google Open Browser http://www.google.com chrome ``` -------------------------------- ### Get Element Count Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the number of elements that match the given locator. This is useful for asserting the quantity of elements on a page. New in Selenium2Library 3.0. ```RobotFramework ${count} = Get Element Count name:div_name Should Be True ${count} > 2 ``` -------------------------------- ### Get Element Attribute Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves the value of a specified attribute from an element. The attribute can be passed as part of the locator or as a separate argument. Using the explicit attribute argument is recommended. ```RobotFramework ${id} = Get Element Attribute css:h1 id ``` -------------------------------- ### Go To Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Navigates the active browser instance to the provided URL. ```APIDOC ## Go To ### Description Navigates the active browser instance to the provided URL. ### Method POST ### Endpoint /go_to ### Parameters #### Query Parameters - **url** (string) - Required - The URL to navigate to. ``` -------------------------------- ### Get Selenium Implicit Wait Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves the current implicit wait value used by Selenium. The value is returned as a human-readable string, for example, '1 second'. More information can be found in the 'Implicit wait' section. ```APIDOC ## Get Selenium Implicit Wait ### Description Gets the implicit wait value used by Selenium. The value is returned as a human readable string like `1 second`. See the [Implicit wait] section above for more information. ### Arguments None ``` -------------------------------- ### Create Webdriver Instance with Proxy Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Demonstrates how to create a Firefox WebDriver instance configured with a proxy. Also shows how to set up a PhantomJS instance with service arguments for proxy configuration. ```RobotFramework # Use proxy with Firefox ${proxy} = Evaluate sys.modules['selenium.webdriver'].Proxy() ${proxy.http_proxy} = Set Variable localhost:8888 Create Webdriver Firefox proxy=${proxy} # Use proxy with PhantomJS ${service args} = Create List --proxy=192.168.132.104:8888 Create Webdriver PhantomJS service_args=${service args} ``` -------------------------------- ### Get Cookies Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns all cookies of the current page. The cookie information is returned as a single string in format `name1=value1; name2=value2; name3=value3`. It can be used, for example, for logging purposes or in headers when sending HTTP requests. ```APIDIDOCOC ## Get Cookies ### Description Returns all cookies of the current page in a string format. ### Returns * A string containing all cookies in the format `name1=value1; name2=value2; ...`. ``` -------------------------------- ### Get Table Cell Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the content of a table cell. The table is identified by the `locator`, and the specific cell is found using `row` and `column` indexes. Both indexes start from 1 and can be negative to count from the end. Header and footer rows are included in the count. See the 'Locating elements' section for locator syntax details. ```APIDOC ## Get Table Cell ### Description Returns contents of table cell. The table is located using the `locator` argument and its cell found using `row` and `column`. See the [Locating elements] section for details about the locator syntax. Both row and column indexes start from 1, and header and footer rows are included in the count. It is possible to refer to rows and columns from the end by using negative indexes so that -1 is the last row/column, -2 is the second last, and so on. ### Arguments * `locator`: The locator for the table element. * `row`: The row index of the cell (starts from 1). * `column`: The column index of the cell (starts from 1). * `loglevel` (optional): The log level for the operation. Defaults to INFO. ``` -------------------------------- ### Open Browser and Switch Between Browsers Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Demonstrates opening multiple browsers and switching between them using index or alias. It's important to manage browser indices carefully, especially when opening new browsers without closing existing ones. ```robotframework Open Browser http://google.com ff Location Should Be http://google.com Open Browser http://yahoo.com ie alias=second Location Should Be http://yahoo.com Switch Browser 1 # index Page Should Contain I'm feeling lucky Switch Browser second # alias Page Should Contain More Yahoo! Close All Browsers ``` ```robotframework ${index} = Open Browser http://google.com # Do something ... Switch Browser ${index} ``` -------------------------------- ### Get Cookie Value Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deprecated. Use `Get Cookie` instead. ```APIDOC ## Get Cookie Value ### Description Deprecated. Use `Get Cookie` instead. ### Arguments * `name` - The name of the cookie. ### Returns * Cookie value. ``` -------------------------------- ### Get Selenium Speed Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Gets the delay configured to wait after each Selenium command. The delay is returned as a human-readable string, such as '1 second'. Refer to the 'Selenium Speed' section for further details. ```APIDOC ## Get Selenium Speed ### Description Gets the delay that is waited after each Selenium command. The value is returned as a human readable string like `1 second`. See the [Selenium Speed] section above for more information. ### Arguments None ``` -------------------------------- ### Get Horizontal Position Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns horizontal position of element identified by `locator`. The position is returned in pixels off the left side of the page, as an integer. See also `Get Vertical Position`. ```APIDOC ## Get Horizontal Position ### Description Returns the horizontal position (X-coordinate) of an element. ### Arguments * `locator` - The locator for the element. ### Returns * The horizontal position of the element in pixels from the left side of the page. ``` -------------------------------- ### Wait For Condition Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Waits until a JavaScript condition is true or a timeout expires. The condition must be a JavaScript expression that returns a value. Examples show waiting for title changes or AJAX requests to complete. ```RobotFramework Wait For Condition return document.title == "New Title" ``` ```RobotFramework Wait For Condition return jQuery.active == 0 ``` ```RobotFramework Wait For Condition style = document.querySelector('h1').style; return style.background == "red" && style.color == "white" ``` -------------------------------- ### Waiting for Elements and Conditions Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Illustrates how to implement waits to ensure elements are ready before interacting with them, preventing race conditions. Use explicit waits for better control. ```robotframework Wait Until Page Contains Element id=results_table timeout=10s Wait Until Element Is Visible xpath=//div[@class='loading-indicator'] timeout=5s ``` -------------------------------- ### Get Cookie Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns information about a cookie with the given name. ```APIDOC ## Get Cookie ### Description Returns information of cookie with `name` as an object. If no cookie is found with `name`, keyword fails. The cookie object contains details about the cookie. ### Method Get Cookie ### Parameters #### Arguments - **name** (string) - The name of the cookie to retrieve. ### Response #### Success Response - **cookie** (object) - An object containing cookie details with attributes: `name`, `value`, `path`, `domain`, `secure`, `httpOnly`, `expiry` (Python datetime object). ### Request Example ```robotframework Add Cookie foo bar ${cookie} = Get Cookie foo Should Be Equal ${cookie.name} bar Should Be Equal ${cookie.value} foo ``` ``` -------------------------------- ### Taking Screenshots Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Demonstrates how to capture a screenshot of the current browser window. This is useful for debugging and reporting. ```robotframework Capture Page Screenshot my_screenshot.png ``` -------------------------------- ### Open Browser Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Opens a new browser instance to the given URL. Supports various browsers and remote Selenium server configurations. ```APIDOC ## Open Browser ### Description Opens a new browser instance to the given URL. The `browser` argument specifies which browser to use. Supported browsers include Firefox, Chrome, Internet Explorer, Edge, Safari, Opera, Android, iPhone, PhantomJS, and HTMLUnit. ### Method Open Browser ### Parameters #### Arguments - **url** (string) - Required - The URL to open in the browser. - **browser** (string) - Optional - Defaults to 'firefox'. The browser to use. - **alias** (string) - Optional - An alias for the browser instance, used for switching between browsers. - **remote_url** (string) - Optional - The URL for a remote Selenium server. - **desired_capabilities** (dict or string) - Optional - Desired capabilities for the remote server, e.g., for proxy configuration or browser/OS selection. - **ff_profile_dir** (string) - Optional - Directory for the Firefox profile. ``` -------------------------------- ### Get Cookie Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns information of cookie with `name` as an object. New in Selenium2Library 3.0. ```APIDOC ## Get Cookie ### Description Returns information of cookie with `name` as an object. ### Arguments * `name` - The name of the cookie. ### Returns * Cookie information as an object. ``` -------------------------------- ### Create Webdriver Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Creates an instance of Selenium WebDriver. This keyword allows for direct initialization of WebDriver instances, offering more control than `Open Browser` for specific configurations. ```APIDOC ## Create Webdriver ### Description Creates an instance of Selenium WebDriver. This keyword allows for direct initialization of WebDriver instances, offering more control than `Open Browser` for specific configurations. ### Method Not applicable (keyword-based) ### Endpoint Not applicable (keyword-based) ### Parameters #### Arguments - **driver_name** (string) - Required - The name of the WebDriver implementation (e.g., Firefox, Chrome, Ie). - **alias** (string) - Optional - An alias for the WebDriver instance. - **kwargs** (dictionary) - Optional - A dictionary of arguments to pass to the WebDriver instance. - ****init_kwargs** - Optional - Keyword arguments to pass directly to the WebDriver constructor. ### Request Example ```robotframework # Use proxy with Firefox ${proxy}= Evaluate sys.modules['selenium.webdriver'].Proxy() ${proxy.http_proxy}= Set Variable localhost:8888 Create Webdriver Firefox proxy=${proxy} # Use proxy with PhantomJS ${service args}= Create List --proxy=192.168.132.104:8888 Create Webdriver PhantomJS service_args=${service args} ``` ### Response #### Success Response Returns the index of the created browser instance. ``` -------------------------------- ### Instantiate Selenium2Library in Python Source: https://context7.com/robotframework/selenium2library/llms.txt Import and instantiate `Selenium2Library` directly in Python code. This allows using its keywords as methods on the library instance, similar to how it's done in Robot Framework. It's useful for extending the library or using it in Python-based test frameworks. ```python from Selenium2Library import Selenium2Library # Instantiate the library (thin wrapper around SeleniumLibrary) lib = Selenium2Library(timeout=10, implicit_wait=0) # The library version print(lib.ROBOT_LIBRARY_VERSION) # 3.0.0 # All SeleniumLibrary keywords are available via the same instance # e.g., lib.open_browser("https://example.com", "Chrome") ``` -------------------------------- ### Select Window Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Selects a browser window based on a locator. Subsequent commands will be executed in the context of the selected window. The previous window handle is returned. ```APIDOC ## Select Window ### Description Selects browser window matching `locator`. If the window is found, all subsequent commands use the selected window until this keyword is used again. If the window is not found, this keyword fails. The previous window handle is returned. The `locator` can be specified using different strategies: - By default, `locator` is matched against window handle, name, title, and URL. - Explicit strategy using format `strategy:value` or `strategy=value`. Supported strategies are `name`, `title`, and `url`. - `NEW` (case-insensitive): Selects the latest opened window. - `MAIN` (default, case-insensitive): Selects the main window. - `CURRENT` (case-insensitive): Does nothing, returns the current window handle. - If `locator` is not a string, it is expected to be a list of window handles to exclude. ### Parameters - **locator** (string or list) - Required - The locator for the window to select. Can be a string or a list of window handles to exclude. ``` -------------------------------- ### Verify Checkbox Not Selected Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Verifies if a checkbox identified by a locator is not currently selected. ```Robot Framework Checkbox Should Not Be Selected my_checkbox_locator ``` -------------------------------- ### Get Table Cell Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the contents of a table cell. It can find cells anywhere within a table. ```APIDOC ## Get Table Cell ### Description Returns contents of table cell. It can find cells anywhere within a table. ### Arguments * locator: The locator for the table cell. ``` -------------------------------- ### Import Selenium2Library in Robot Framework Source: https://context7.com/robotframework/selenium2library/llms.txt Declare Selenium2Library in a .robot test suite to access browser-control keywords. The library accepts arguments like timeout and implicit_wait. ```robotframework *** Settings *** Library Selenium2Library timeout=10 implicit_wait=0 run_on_failure=Capture Page Screenshot *** Variables *** ${BROWSER} Chrome ${BASE_URL} https://example.com ``` -------------------------------- ### Locating and Interacting with Elements Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Shows how to find elements on a web page using various locators and perform actions like clicking or typing. Use specific locators for reliable element identification. ```robotframework Click Element id=my_button Input Text xpath=//input[@name='username'] my_username Get Text css=.page-title # Example of getting text ``` -------------------------------- ### Delete All Cookies Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deletes all cookies from the browser. This is useful for starting a test session with a clean cookie state. ```APIDOC ## Delete All Cookies ### Description Deletes all cookies from the browser. This is useful for starting a test session with a clean cookie state. ### Method Not applicable (keyword-based) ### Endpoint Not applicable (keyword-based) ``` -------------------------------- ### Open Browser Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Opens a new browser instance to the given URL. Supports various browsers and remote WebDriver configurations. ```APIDOC ## Open Browser ### Description Opens a new browser instance to the given `url`. ### Method N/A (Keyword) ### Parameters - **url** (string) - Required - The URL to open. - **browser** (string) - Optional - The browser to use (e.g., Chrome, Firefox, Edge). - **alias** (string) - Optional - An alias for the browser instance. - **remote_url** (string) - Optional - The URL of the remote WebDriver server. - **desired_capabilities** (string) - Optional - Desired capabilities for the browser. - **ff_profile_dir** (string) - Optional - Path to a Firefox profile directory. ### Examples ```robotframework Open Browser http://example.com Chrome Open Browser http://example.com Firefox alias=Firefox Open Browser http://example.com Edge remote_url=http://127.0.0.1:4444/wd/hub ``` ``` -------------------------------- ### Get Value Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the value attribute of an element identified by a locator. This is commonly used for form input elements. ```APIDOC ## Get Value ### Description Returns the value attribute of element identified by locator. ### Arguments * locator: The locator for the element. ``` -------------------------------- ### Go Back Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Simulates the user clicking the back button on their browser. ```APIDOC ## Go Back ### Description Simulates the user clicking the back button on their browser. ### Method POST ### Endpoint /go_back ``` -------------------------------- ### Get Alert Message Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deprecated. Use `Handle Alert` instead. Returns the message of the alert and dismisses it by default. ```APIDOC ## Get Alert Message ### Description Deprecated. Use `Handle Alert` instead. Returns the message the alert has. Dismisses the alert by default (i.e. presses `Cancel`) and setting `dismiss` to false leaves the alert open. There is no support to accept the alert (i.e. to press `Ok`). ### Method Get Alert Message ### Parameters #### Arguments - **dismiss** (boolean, optional) - If True, dismisses the alert. Defaults to True. ``` -------------------------------- ### Open Context Menu Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Opens the context menu on an element identified by a locator. ```APIDOC ## Open Context Menu ### Description Opens context menu on element identified by `locator`. ### Method N/A (Keyword) ### Parameters - **locator** (string) - Required - The locator for the element. ### Examples ```robotframework Open Context Menu xpath=//button[@id='myButton'] ``` ``` -------------------------------- ### Get Vertical Position Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the vertical position of an element identified by a locator. The position is returned in pixels from the top of the page. ```APIDOC ## Get Vertical Position ### Description Returns vertical position of element identified by locator. ### Arguments * locator: The locator for the element. ### Returns * Integer: The vertical position in pixels. ``` -------------------------------- ### Get Title Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the title of the current web page. This is typically displayed in the browser tab or window title bar. ```APIDOC ## Get Title ### Description Returns the title of current page. ### Arguments None ``` -------------------------------- ### Get Text Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the text value of an element identified by a locator. This is useful for extracting visible text from web pages. ```APIDOC ## Get Text ### Description Returns the text value of element identified by locator. ### Arguments * locator: The locator for the element. ``` -------------------------------- ### Reload Page Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Simulates a user reloading the current web page. ```Robot Framework Reload Page ``` -------------------------------- ### Set Screenshot Directory Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Configures the directory where screenshots will be saved. If the directory does not exist, it will be created. The previous directory path is returned. ```APIDOC ## Set Screenshot Directory ### Description Sets the directory for captured screenshots. ### Method (Implicitly a keyword call in Robot Framework) ### Parameters #### Path Parameters - **path** (string) - Required - The absolute path to the directory where screenshots should be written. ### Example ```robotframework ${previous_dir} = Set Screenshot Directory /path/to/screenshots ``` ``` -------------------------------- ### Select Window Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Selects a browser window based on its handle or title. It can also be used to select the main window or a window identified by a variable. ```APIDOC ## Select Window ### Description Selects browser window matching `locator`. ### Method (Implicitly a keyword call in Robot Framework) ### Parameters #### Path Parameters - **handle** (string) - Required - The window handle or identifier to select. ### Example ```robotframework Select Window ${handle} Select Window MAIN Select Window ${excludes} ``` ``` -------------------------------- ### Get Window Position Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns the current window's position relative to the top-left corner of the screen. The position is returned as integers. ```APIDOC ## Get Window Position ### Description Returns current window position. ### Arguments None ### Returns * Tuple: A tuple containing the x and y coordinates of the window. ``` -------------------------------- ### Simulate Key Press on Element Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Simulates a user pressing a key on a specified element. The key can be a single character, a string, or an ASCII code prefixed with '\\'. ```Robot Framework Press Key text_field q ``` ```Robot Framework Press Key text_field abcde ``` ```Robot Framework Press Key login_button \\13 # ASCII code for enter key ``` -------------------------------- ### Set Window Size Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Sets the current browser window size to the specified width and height. ```APIDOC ## Set Window Size ### Description Sets current windows size to given `width` and `height`. ### Arguments * `width`: The desired width of the window. * `height`: The desired height of the window. ### Notes Browsers have a minimum size limit; attempting to set a smaller size may result in a larger actual size. ``` -------------------------------- ### Use Custom Locator Strategy Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Utilize a registered custom locator strategy to find and interact with elements. The 'custom:' prefix is used, followed by the strategy name and the locator criteria. ```Robot Framework Click Element custom:example ``` -------------------------------- ### Handle Alert Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Handles the next alert, confirmation, or prompt. This keyword replaces the deprecated `Confirm Action` and allows specifying the action to take. ```APIDOC ## Handle Alert ### Description Handles the next alert, confirmation, or prompt. This keyword replaces the deprecated `Confirm Action` and allows specifying the action to take. ### Method Not applicable (keyword-based) ### Endpoint Not applicable (keyword-based) ### Parameters #### Arguments - **accept** (boolean) - Optional - Whether to accept (True) or cancel (False) the alert. Defaults to True. ``` -------------------------------- ### Select All From List Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Selects all options from a multi-selection list. Ensure the locator correctly identifies the list element. ```APIDOC ## Select All From List ### Description Selects all options from multi-selection list See the Locating elements section for details about the locator syntax. ### Arguments * `locator` ``` -------------------------------- ### Choose Cancel On Next Confirmation (Deprecated) Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html This keyword is deprecated and should not be used. Use 'Handle Alert' directly instead. ```Robot Framework Choose Cancel On Next Confirmation ``` -------------------------------- ### Choose File Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Inputs the file_path into a file input field identified by locator. This is typically used for uploading files via web forms. The file must exist on the execution machine. ```APIDOC ## Choose File ### Description Inputs the `file_path` into file input field `locator`. This keyword is most often used to input files into upload forms. The file specified with `file_path` must be available on machine where tests are executed. ### Method (Not specified, typically a keyword in a testing framework) ### Parameters #### Arguments - **locator** (string) - The locator for the file input field. - **file_path** (string) - The path to the file to be uploaded. ### Example ```robotframework Choose File my_upload_field ${CURDIR}/trades.csv ``` ``` -------------------------------- ### Verify Table Cell Content Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Checks if a specific table cell contains the expected text. This keyword relies on 'Get Table Cell' internally for locating the cell. ```robotframework Table Cell Should Contain id=my_table 1 2 Expected Text ``` -------------------------------- ### Migrate Robot Framework Tests from Selenium2Library to SeleniumLibrary Source: https://context7.com/robotframework/selenium2library/llms.txt To migrate from `Selenium2Library` to `SeleniumLibrary`, update the `Library` import in the Settings section. Fully-qualified keyword calls (e.g., `Selenium2Library.Title Should Be`) can be simplified to just the keyword name (`Title Should Be`) if `SeleniumLibrary` is the only browser library loaded. ```robotframework # Before migration *** Settings *** Library Selenium2Library *** Test Cases *** Old Style Call Selenium2Library.Title Should Be Example Domain # After migration *** Settings *** Library SeleniumLibrary *** Test Cases *** New Style Call SeleniumLibrary.Title Should Be Example Domain # Or simply (no library prefix needed when only one browser library is loaded): Title Should Be Example Domain ``` -------------------------------- ### Location Should Be Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Verifies that current URL is exactly url. See the Locating elements section for details about the locator syntax. ```APIDOC ## Location Should Be ### Description Verifies that current URL is exactly url . ### Arguments * `url` - The expected URL. ``` -------------------------------- ### Set Window Size Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Resizes the browser window to a specified width and height. Input can be numeric or string values. Browsers have minimum size limits, so requesting a size smaller than the minimum may result in a larger actual size. ```robotframework Set Window Size 800 600 ``` -------------------------------- ### Get Selenium Timeout Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves the timeout value used by various keywords. The timeout is presented as a human-readable string, for instance, '1 second'. Further details are available in the 'Timeout' section. ```APIDOC ## Get Selenium Timeout ### Description Gets the timeout that is used by various keywords. The value is returned as a human readable string like `1 second`. See the [Timeout] section above for more information. ### Arguments None ``` -------------------------------- ### Switch Browser Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Switches between active browsers using an index or an alias. This is crucial for managing multiple browser instances during testing. ```APIDOC ## Switch Browser ### Description Switches between active browsers using `index_or_alias`. ### Arguments * index_or_alias: The index (starting from 1) or alias of the browser to switch to. ``` -------------------------------- ### Get Cookie Information Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves information about a specific cookie by its name. The cookie object contains attributes like name, value, path, domain, secure, httpOnly, and expiry. ```robotframework ${cookie} = Get Cookie foo ``` -------------------------------- ### Element Should Be Enabled Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Verifies that an element is enabled. ```APIDOC ## Element Should Be Enabled ### Description Verifies that element identified with `locator` is enabled. This keyword considers also elements that are read-only to be disabled. See the [Locating elements](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Locating%20elements) section for details about the locator syntax. ### Arguments * `locator`: The locator of the element to check. ``` -------------------------------- ### Locator Should Match X Times Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deprecated, use Page Should Contain Element with limit argument instead. ```APIDOC ## Locator Should Match X Times ### Description Deprecated, use `Page Should Contain Element` with limit argument instead. ### Arguments * `locator` - The locator to check. * `x` - The expected number of times the locator should match. * `message` - Optional custom error message. * `loglevel` - Optional log level. ``` -------------------------------- ### Get Element Attribute Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Returns value of `attribute` from element `locator`. Passing attribute name as part of the `locator` is deprecated since Selenium2Library 3.0. The explicit `attribute` argument should be used instead. ```APIDOC ## Get Element Attribute ### Description Returns the value of a specified attribute from a given element. ### Arguments * `locator` - The locator for the element. * `attribute` - The name of the attribute to retrieve (defaults to None). ### Returns * The value of the specified attribute. ``` -------------------------------- ### Select From List Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Deprecated: Use Select From List By Label/Value/Index instead. This keyword is slow and complicated for selecting options. ```APIDOC ## Select From List ### Description Deprecated. Use Select From List By Label/Value/Index instead. This keyword selects options based on labels or values, which makes it very complicated and slow. It has been deprecated in Selenium2Library 3.0, and dedicated keywords Select From List By Label, Select From List By Value and Select From List By Index should be used instead. ### Arguments * `locator` * `*options` ``` -------------------------------- ### Get Selected List Value Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Retrieves the value of the selected option from a selection list. If multiple options are selected, it returns the value of the first one. The locator syntax is explained in the 'Locating elements' section. ```APIDOC ## Get Selected List Value ### Description Returns value of selected option from selection list `locator`. If there are multiple selected options, value of the first option is returned. See the [Locating elements] section for details about the locator syntax. ### Arguments * `locator`: The locator for the selection list element. ``` -------------------------------- ### Create a Matcher Object Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Creates a Matcher object that can test if a string matches a given pattern. Supports wildcard characters '?' for single characters and '*' for any sequence of characters. ```javascript function Matcher(pattern) { pattern = regexpEscape(normalize(pattern)); var rePattern = '^' + pattern.replace(/\\\?/g, '.').replace(/\\\ acilitates/g, '[\\s\\S]*') + '$'; var regexp = new RegExp(rePattern); function matches(string) { return regexp.test(normalize(string)); } return { matches: matches, matchesAny: function (strings) { for (var i = 0, len = strings.length; i < len; i++) if (matches(strings[i])) return true; return false; } }; } ``` -------------------------------- ### Verify Table Column Content Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Verifies if a table column contains specific text. Column indexing starts from 1 and supports negative indexing from the end. Merged cells are treated as single columns. ```robotframework Table Column Should Contain id=my_table 1 Expected Text ``` -------------------------------- ### Input Text Into Alert Example Source: https://github.com/robotframework/selenium2library/blob/master/docs/Selenium2Library.html Types text into an input field within an alert. The alert is accepted by default, but this can be changed using the 'action' argument. A timeout can also be specified. New in Selenium2Library 3.0. ```Robot Framework Input Text Into Alert text ```