Search code examples
pythonrobotframeworkrobotframework-pythonremoteserver

how to locate an id of the button to click when id is dynamic in robot framework


I am new to robot framework and learned few basics of robot framework. when i tried to create a new account in facebook , i have used id element of "create new account" but everytime new id is generated when its open an new page. can someone help to make me understand how to click a button when id is dynamic.

*** Settings ***

Library    SeleniumLibrary

*** Test Cases ***

facebooklogin

    open browser    https://www.facebook.com/    firefox
    maximize browser window
    set selenium timeout    10s
    click button    id:u_0_d_si

Error message : Button with locator 'id:u_0_d_si' not found.


Solution

  • Just use proper locator strategy of the element, since you have used the id attribute of element, but if you refresh the page every time it will change, meaning id attribute value is dynamic, where as you can go for text of the element to identify it every time uniquely.

    *** Test Cases ***
    Create new facebook account
    
        Open Browser    https://www.facebook.com/    firefox
        Maximize Browser Window
        Set Selenium Timeout    10s
        Click Element    xpath:.//a[text()="Create New Account"]