Commonly, object locators are easily broken or unable to identify the target element when the application under test (AUT) changes
So wanted to check in case any test case /step fails to find an object with its default locator, Can it tries other pre-configured locators associated with that object.
Is there any way with which we can achieve this.
If it’s possible then then rather than failing the step ,it checks with other xpaths and make script smart enough to continue execution.
Not out of the box, at least with SeleniumLibrary. But it’s always possible to build your own extension which does what you want. But I would think it would be better to make your team also fix the tests. Who changed the product/SUT should also fix the tests.
Tatu is correct. I don’t know of a way in RF, or in SeleniumLibrary to be exact since it sounds like you are talking about web app tests automation that you can provide multiple different locators for the same element and have the automation try, say all 3, for a given button. I’ve heard of other tools where you can do something like that. Personally I dislike the approach.
The best you could do is how you write your locators in such a way that they are not so tight and hardcoded and brittle. For example, don’t use text() = ‘some fixed text’ but instead use contains. Or just don’t cue off of text or labels but use other HTML attributes to construct your locators.
XPath does have a way to specify OR clauses for your locators so that could gain you some flexibility but it’s rather advanced stuff and if you are hoping to do that for all of your locators it’s going to take you forever!
Making the automated test script “smart” enough, or I prefer to way flexible enough is really up to you the author of the script, really the author of the locators/selectors.
you can try to change your location generate method. whether you can auto generate your locator from frontend source code. before your test scripts execution, you can update your locator automatically. even if urly xpath, it also can accept. it will save more cost for your selenium testing.
I agree with hobet. In addition you can set guidelines or standards just like what hobet said about hardcoded locator values and specifying texts. you can also set a standard with your developers. You can set a specific attribute as your web locator.
we use python beautifulsoap library to analyse html code. and generate the xpath automatically for each element. we no need to write the location by ourself. and if code change something to make xpath change, we can automatic generate again before each automation scripts run.
How long have you been doing this @nixuewei? Years? So essentially you are “calculating” or like you said, programmatically generating your XPath locators? All of the locators you use in your automated tests are done using XPath? No ID attributes or CSS?
i just provide a new view to generate the location path. currently my project foucs on api testing. you can generate by priority, id and name is first priority, then css or xpath.