xpathrobotframework

Why am I getting an element not found error when my xpath locator is correct?


I am trying to use the explicit locator strategy in the Selenium Robot library to find an element:

Click Element    xpath://*[@id="sidebar-nav"]

I can locate the element using this xpath on the web console, but when I run my Robot test I'm getting an element not found error. I haven't been able to locate it using css either. What am I doing wrong?


Solution

  • It's usually one of two things:

    1. You need to wait for the element
    2. The element is in an IFRAME or shadow-dom

    If you need to add waits, use things like

    1. Wait Until Element Is Visible
    2. Wait Until Element Is Not Visible
    3. Wait Until Page Contains Element
    4. Wait Until Page Does Not Contain Element

    See the docs, https://github.com/robotframework/HowToWriteGoodTestCases/blob/master/HowToWriteGoodTestCases.rst#avoid-sleeping