Is there a way to capture the value by using the id of a tagName, when the id is dynamic. Eg: My id value currently is id="m_7959323670053369637verificationMsg" but the "verificationMsg" remains same, only the number keeps changing. I know this question isn't clear, but I can't find a better way to put it. What I am actually trying to do is, I am trying to capture the value that I get in the mail (the verification code), but the id is dynamic in the htmltag, and it is the closest that I can get to point out the value. I hope my question is understood.
You can use the xpath for this type element to locate like
//*[contains(@id,'verificationMsg')]
or
//*[ends-with(@id,'verificationMsg')]
you can use CSS identifier as well. Following will find any element which ends with
[id$='verificationMsg']
this one would also works, but it checks if string contains.
[id*='verificationMsg']
in case you need something which starts with you can use following
[id^='verificationMsg']
You can use xpath's ends-with method. Something like below example-
WebElement cls=ff.findElement(By.xpath("//*[ends-with(@id,'verificationMsg')]"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.