RE: Advise on location elements on a webpage I am buildong a selenium script for
Hi there, I am after some advice regarding a Selenium script I am building. As can be seen from the screenshot attached I am hovering over the ‘Reports’ text from the navigation pane which brings up a menu…..from there I am selecting ‘Asset Management’, then ‘Terminated Report: Completed’ from the sub-menu.
I’ve also attached the code (‘Selenium Code’
The issue I have had is that, as can be seen from Screenshot 1, I want to arrive at Asset Management > Terminated Report: Completed. After I have checked that page I want to go to Asset Management > Terminated Report: Pending. However, the XPath when selecting the ‘Asset Management’ option is now different, even thought the selection of it is the same as before. I’m assuming this is because I am selecting it from a different page. Based on the above, I have two questions which I am hoping for assistance on:
1) Given that it looks like XPath isn’t the best way of me navigating through this navigation menus, what would be the best element locator to use, in order to get to the desired location? Hopefully, the screenshots provide enough detail.
2) Another issue I have is that when I
Apologies for the long-winded questions, but I just wanted to make sure I explained it all correctly. Any help would be greatly appreciated.
First I would like to appreciate your effort you put to write this question beautifully. I wish everybody follow these standards, it easy for us to investigate.
Now coming back to you questions
Question 1 : Avoid using Absolute xpaths, always prefer relative xpaths. Please read this article, you will find your answers by your own:
Question 2: I think the only problem is with when you are clicking the ‘Terminate Report Complete‘. In your Page Object I can see that you are using action class for mouse hovering on this element to. But actually you do not need to mouse hover to click this element. So just change your Page Object of ‘TerminateReportCompleteFocus‘ function and directly use click() to perform click. I think by following this your second problem will also resolve.
Suggestion : Make use of FirePath tool of Firefox. It will automatically give you the absolute xpath.
Do not forget to close the question, if it resolve your issue.