Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20



Selenium Robot Framework Assign Element Id

In this example, you will learn how to use Selenium2Library to handle web elements with no Id or with dynamic locators in web application testing. Selenium2Library has keywords: Assign Id To Element. This keyword is very important if you need to define static id to elements that has very dynamic value or no id locator.


Step 1: launch RIDE console, add a resource file named "resource.txt". In this resource file, import Selenium2Library and OperatingSystem library. Add a variable ${Browser}=Firefox.  This resource file will be used in the test.

When view the resource.text in the "Text Edit" view, it looks like this.

Step 2: add a new Suite named "AssignIdToElementKeywords". In this suite, import the resource.txt file as Resource and add a test case named "AssignIdToElementTest".

Test Case Keywords view looks like this

*** Settings ***
Resource          ../resource.txt

*** Test Cases ***
    Open Browser    ${Browser}
    Maximize Browser Window
    Assign Id To Element    name=login_username    id=login_button
    sleep    10s
    Page Should Contain Element    id=login_button
    Close Browser

Step 4: run the test as pybot and see the result. Test passed. see the result file at this location below.