Unable to get XPath as values and location is changing

262 views Asked by At

I have one application under test. I want to test the numbers and verify with expected values using robot framework. As values and location is changing after importing one file it is hard to get the xpaths. I tried with all the xpaths like with Selectors Hub OR normal chrome xpath. How to get these values as it is constantly changing the values and location.

On importing one file it displays as; enter image description here

When importing further files values as location is keep changing like below. enter image description here

and so on

enter image description here

2

There are 2 answers

0
Michael Kay On

Firstly, I think you should be using a screen-scraping tool like Selenium only to test that the visual output of the tool is correctly formatted. If it's your application, then it should have an API (for example a REST API that delivers XML or JSON) that produces results in structured format, and use of that API should be your primary way of testing that the information content of the application's output is correct.

Secondly, yes, this is the problem with screen-scraping. If the output is completely predictable then you don't need to look at the HTML because it's always the same. If it's completely unpredictable then there is no way of distinguishing correct output from incorrect output. You need to ask yourself carefully: (a) what are the fixed properties of the output that I can always rely upon, (b) what are the properties that will vary, but which I want to test are as expected, and (c) how do I locate (b) relative to (a).

In your example if you want to test that there is a table cell with the text "Cows" immediately adjacent to a table cell with the text "25" then it's perfectly possible to do that with XPath -- even the antiquated XPath 1.0 which is the only version that Selenium offers.

0
ADS KUL On

It worked with below line.

//button[@title='Cows']/span[2]