The most common error faced by beginners is "Element not found" . There are multiple reasons for this error to occur, so there are multiple solutions for the problem. Below are some of the common diagnosing techniques I learned with time and would like to share with you people. These techniques could be helpful or may be not, depending on your problem.
" You have used the correct id/xpath and when you inspect the element, Its visible. But , on runtime you are facing the error. "
Solutions - Check that your id/xpath should not result in 2 elements while inspecting element. Normally, what happens that developer re-uses the same code for some elements if the functionality is repeated . This results in duplicate value in a page. So, Inspecting element may highlight the element you want but in code that element falls under different category and will result in error. Move to the duplicate element using indexing or following commands and see if it helps you.
- Use .isDisplayed() and .isEnabled() methods on the element. This will result in true or false. If one them results in false then you have to diagnose ahead. Sometimes, the element is present while inspecting, in the code as well but not visible on the screen. In those cases .isDisplayed() results false. Scroll your page and make the element visible on page and then try working on it. If .isEnabled is false then the element is hidden. You have to first diagnose that how and why this happens, Contact your developer in this case and ask him to correct if its a problem in his code.
- Add some wait before accessing the element. This scenario is usually for the ajax elements. The elements may vary on loading time according to your connection and will result in error. Use Explicit wait or normal Thread.sleep();
- Element is visible on the screen but present under the Iframe and not inspectable. Iframes are concept of page under a page, They are the part of the main code but to access element present inside iframe needs switching to an iframe. Switch and use id/xpath to inspect the element.
Post comments below if these solutions helped you in some way or even solved your problem. If not, lets try working together to find a solution :)
" You have used the correct id/xpath and when you inspect the element, Its visible. But , on runtime you are facing the error. "
Solutions - Check that your id/xpath should not result in 2 elements while inspecting element. Normally, what happens that developer re-uses the same code for some elements if the functionality is repeated . This results in duplicate value in a page. So, Inspecting element may highlight the element you want but in code that element falls under different category and will result in error. Move to the duplicate element using indexing or following commands and see if it helps you.
- Use .isDisplayed() and .isEnabled() methods on the element. This will result in true or false. If one them results in false then you have to diagnose ahead. Sometimes, the element is present while inspecting, in the code as well but not visible on the screen. In those cases .isDisplayed() results false. Scroll your page and make the element visible on page and then try working on it. If .isEnabled is false then the element is hidden. You have to first diagnose that how and why this happens, Contact your developer in this case and ask him to correct if its a problem in his code.
- Add some wait before accessing the element. This scenario is usually for the ajax elements. The elements may vary on loading time according to your connection and will result in error. Use Explicit wait or normal Thread.sleep();
- Element is visible on the screen but present under the Iframe and not inspectable. Iframes are concept of page under a page, They are the part of the main code but to access element present inside iframe needs switching to an iframe. Switch and use id/xpath to inspect the element.
Post comments below if these solutions helped you in some way or even solved your problem. If not, lets try working together to find a solution :)
No comments:
Post a Comment