I am trying to capture a drop-menu field using test automation in SELENIUM with chrome driver.
Why does the element "id" changes in some web pages when inspecting elements time to time, with Chrome browser? How to keep the "id"s static, without changing?
Steps I followed:
- When I inspect elements in the web page, the particular drop-menu shows its "id" as: id="combo-1782-inputEl"
HTML:
<input id="combo-1782-inputEl**" type="text" class="x-form-field x-form-required-field x-form-text x-trigger-noedit x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" name="type" readonly="readonly" aria-invalid="false" data-errorqtip="" style="width: 135px;">
id
observed by inspecting the web page in normal chrome browser:
Then I used the above id in my java code(automation script) as below:
driver.findElement(By.id("combo-1782-inputEl")).click();
When I run the test > The google chrome browser opens automatically > The test gets successful till it meets the above line of code.
But, when it meets the above code line, the test failed Throwing the following exception:
- class org.openqa.selenium.NoSuchElementException *
Then I inspected the same drop menu item in chrome web page opened (controlled) by automated test software, and found out that the "id" is different than the previous id mentioned in step 1. The "id" in this case is: "combo-1781-inputEl"
id
observed by inspecting the web page in chrome browser controlled by automated software:
As you can see, the number in the middle of the id has reduced from 1. (1782-1 = 1781)
Same issue was found in the other drop menu items on the same web page.
What is the issue cause for this? How can I overcome this situation? Please help. :)
P.S. When I used "combo-1781-inputEl" ("id" from step 5) in my code, the test passed successfully.
driver.findElement(By.id("combo-1782-inputEl")).click(); //Test: failed
driver.findElement(By.id("combo-1781-inputEl")).click(); //Test: passed
I expected the test to be passed when I used the "id" I got in step 1 by inspecting the web page in normal chrome browser which is not controlled by automated software.