Sometimes the element cannot be located because it has not been created yet. Another action needs to happen on the page to trigger creation of the element – an action that is missing from the testcase.
Example: A common case is clicking on an item in a menu that is only visible after moving the mouse to an element on the page. When the mouse enters the element, the menu is created, which contains the menu item that needs to be clicked. The LogOut option on a WordPress site is a great example:
The Log Out element does not exist until the mouse is moved over the “Howdy, Chris” label.
The solution to the failed step is simple: insert a step immediately before to move the mouse to that element. For example: