I am not able to find the element using "id" in selenium as the id is randomly changing in every session of execution so the same id i am not getting in next execution. As there is no other unique property is there to identify the element.
Asked
Active
Viewed 653 times
-1
-
so, what is the question? please take a look http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist and make more clear your question. – Mahsum Akbas Oct 28 '15 at 11:56
-
What have you tried and what was the result? As you did in school... please show your work. :) It's part of the process of getting questions answered on SO. It's helpful to you because it forces you to investigate your own problem and think it through. It also proves to readers that you did your homework and made a reasonable attempt to answer your own question. Thirdly, it helps readers find and diagnose the problem resulting in a better answer for you and less time wasted for us. – JeffC Oct 28 '15 at 15:22
-
Please post the HTML here instead of a picture. The picture will eventually be unavailable and then the question will be less useful. – JeffC Oct 28 '15 at 15:22
-
Possible duplicate of [Find element by attribute](http://stackoverflow.com/questions/26304224/find-element-by-attribute) – JeffC Oct 28 '15 at 15:22
2 Answers
0
You didn't specify a language so I'm going to give you Java. You can do this by using the CSS class or probably a better choice (because of likely uniqueness) is data-lynx-name
.
By CSS class
driver.findElement(By.cssSelector("div.http-lynx-json-org-text-input"));
By attribute
driver.findElement(By.cssSelector("div[data-lynx-name='username']"));
You really should read the question that I duped this one to: Find element by attribute
Also read more about CSS selectors, http://www.w3.org/TR/selectors/#selectors
0
You can use XPath.
String xpath = //div[@data-lynx-name='usernameLabel'][text='User ID']/following-sibling::div[1]
The above XPath will will find the div
tag containing text 'User ID' and finds the next div
which is is the required textbox.
It seems that you can even use the attribute 'data-lynx-name' attribute of the textbox div
tag directly.
String xpath = //div[@data-lynx-name='username']
Selenium
driver.findElement(By.xpath(xpath));

StrikerVillain
- 3,719
- 2
- 24
- 41