Selenium Automation:- Control ids keep changing

Selenium Automation:- Control ids keep changing

  

I am doing automation using selenium ,  i found that control ids keep changing whenever there is a new addition to the form or if we update the theme.

 The Control ID is the unique internal numeric identifier. It is generally the best method of identifying controls.

Since control ID is changing my original scripts are getting failed. 

Please suggest any solution to work on it. Thank you.

Solution

@Reshma

You'll have to use a different identifier in your scripts.

Consider adding a property with a value that can be static and known to you in the Extended Properties.


Solution

Hello Joao, Thanks for your reply.

This will be from developer's side. They need to set this custom attribute on each field, I think this is not the good way from tester's side.

And also In Selenium, controls are identified by ID, Name and Classes in XPath query language.


Reshma, You can try Epimetheus from the forum.

Hi Reshma,

This can be done at Selenium end itself by using Xpath . So for below  example  you can select the element  by Xpath rather then by ID or name if they are dynamic

So in below case Xpath would be 

By.Xpath("//div/table/tr/td/input")


<div>

      <table>

          <tr>

            <td>

             <input type="text"  id="fname_32" name="fname_32">

            </td>

         </tr>

   </table>

</div>


Regards

Devendra






@Reshma, Joao is right adding a property is the most reliable way to go.  Devendra's idea is good and will work, but you have to update tests whenever screen structure changes.

I find the simplest most reliable way is to add classes to identify components.  This way you can work with classes which is easier in Selenium.

If you are working separately from developers, then yes, this would be something done in Service Studio. It is quite a common practice nowadays to add identifiers in HTML to make automated tests less brittle.

Hope this helps!