Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in DevOps and Agile by (19.7k points)

I have a student text box which accepts a value and search the student in the list below. This is how the console looks for the element for the first time

input type="text" class="studSearch" id="esearch0" name="esearch[0]" 

value="Select student to enable"

When I enter all the values after that and click on "add another student" button, the next time student text box looks like below

input type="text" class="studSearch" id="esearch1" name="esearch[1]" value="Select student to enable"

I am storing the elements in a database and fetching it in the code. I am declaring the initial element in the database as Name = esearch[0] I want a way to write a prog dynamically so that I declare the web element once but use it when I am adding 3 students also one after the other?

1 Answer

0 votes
by (62.9k points)

Your question was “There is no distinctive attribute present (No distinctive class, no distinctive name) & the id keeps on changing after each login thus cannot take id also.”

This is a really common issue with several applications that are used over the internet.

There are four general approaches to fix this:

  1. Look for different existing CSS identifiers like id, class and name used on different elements within the DOM hierarchy of the element, for instance, form#new_user could also be unique could also be form#new_user input. the top may be distinctive even when input.top on its own isn't distinctive and is in other forms on the page.

  2. Look for data- attributes that you can use to identify the element

  3. If operating with the developers, ask them to feature unique CSS identifiers like id, class, name or data attribute to the element or elements within the hierarchy that may be used, together, to uniquely identify the element.

  4. Use the complete XPath of where the element is, however, to remember that this might break with future changes within the page structure

 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...