I want to change the name of the xpaths when i’m using Page should have contained element
so instead of getting an error of :
Page should have contained element ‘xpath:/html/body/div/div[1]/div/div/menu/div/div/form/div[2]/ul/li[4]/ul/li[8]/a’ but did not.
I want the error message to be : Page should have contained element ‘something’ but did not.
Personally i don’t think that’s even a good idea. Someone else looking for error will need to dig into your robot resources, find out where “something” is defined and then check what is its value and only then start digging why the selector is not present in the page.
I’m testing the existence of the header’s menu buttons for a website
So if one of the buttons doesnt show up (let’s say the ‘login’ button)
I want the output file to tell me that : Page should have contained element ‘login’ but did not
instead of the whole long xpath
I would suggest you start with xpaths that are more readable and more robust
Assuming this link is for your login element:
This may fail even when the login button is still on the page, all it would take is for a developer to add another element somewhere else in the page to break this kind of extremely fragile xpath
An xpath like this would likely be more reliable and also make it clear what you are testing for without changing RF: xpath://menu//form//li/a[text()='login']
And it may not even need to be that complicated, as a very simple xpath like this may be all you need if you don’t need to confirm that it is in a specific place and simply want to make sure that there is a link called logon somewhere on the page: xpath://a[text()='login']
Learning how to write good xpaths will save you a lot of effort and make your test cases much more reliable, this is a good place to start XPath Syntax