How to fix "Element with locator not found" in robot framework

10,109

The error is telling you it can't find the element.

There are several reasons that could happen. It could truly not be on the page. Or, it could be that it's not initially on the page but is added asynchronously at some point after your test runs. Or, the element could be inside an iframe. Or, you could be on a different page than you are assuming you're on due to an error or a redirect that you didn't anticipate.

Each of those problems requires a different solution. You may simply have an incorrect locator, in which case you need to determine what the correct locator is and use it instead. Or, you may need to call Wait until page contains element before calling input text. Or, you might need to call Select frame to switch to an embedded frame. Or, you might need to verify you are on the correct page before calling input text.

Share:
10,109
ml33
Author by

ml33

Updated on June 04, 2022

Comments

  • ml33
    ml33 almost 2 years

    I need to write a script where I can search with a keyword and test if a certain subject will show but I cannot manage to get the search id. This is my script.

    *** Settings ***
     Library    SeleniumLibrary
     Suite Setup     Go to homepage
     Suite Teardown     Close All Browsers
    
     *** Variables ***
     ${HOMEPAGE}     https://www.mdh.se/utbildning/kurser
     ${BROWSER}      chrome
    
     *** Test Cases ***
     Google cloud and find Industrial Systems in Cloud Computing
      Google and check results         cloud       Industrial Systems in Cloud Computing
    
     *** Keywords ***
     Google and check results
      [Arguments]         ${searchkey}        ${result}
     Input Text     id=occasionsTableen_UK_filter     ${searchkey}
     Wait Until Page Contains      ${result}
     Go to homepage
      Open Browser     ${HOMEPAGE}     ${BROWSER}
    

    And this is the error message

     Google cloud and find Industrial Systems in Cloud Computing           | FAIL |
     Element with locator 'id=occasionsTableen_UK_filter' not found.
    
    • Rotrak
      Rotrak over 4 years
      Tried simply to remove the 'id='? Does that help?
    • ml33
      ml33 over 4 years
      Element with locator 'occasionsTableen_UK_filter' not found. @Rotrak Thats what it says now
    • M.M.
      M.M. over 4 years
      you could you try it with xpath://*[@id="occasionsTableen_UK_filter"]/label/input
  • ml33
    ml33 over 4 years
    When I inspect the search bar this is what I get and thats why I dont know how to call it as it doesnt have a name or id. @asprtrmp <input type="search" class="" placeholder="Search courses" aria- controls="occasionsTableen_UK">
  • asprtrmp
    asprtrmp over 4 years
    For me the element's attribute is occasionsTablesv_SE. But you can use xpath based on attribute value, e.g, the locator usage in Selenium would be like xpath=//input[@aria-controls='occasionsTablesv_SE']
  • George Wurthmann
    George Wurthmann over 3 years
    In my case the age use an iframe.