[英]Is there a way to capture the value by using the id of a tagName, when the id is dynamic
Is there a way to capture the value by using the id of a tagName, when the id is dynamic. 当id是动态的时,是否可以通过使用tagName的id来捕获值。 Eg: My id value currently is id="m_7959323670053369637verificationMsg" but the "verificationMsg" remains same, only the number keeps changing. 例如:我的id值当前为id =“ m_7959323670053369637verificationMsg”,但“ verificationMsg”保持不变,只是数字不断变化。 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. 我实际上想做的是,我试图捕获在邮件中获得的值(验证码),但是id在htmltag中是动态的,它是我能指出的最接近的值。值。 I hope my question is understood. 希望我的问题能被理解。
You can use the xpath for this type element to locate like 您可以使用xpath将此类型元素定位为
//*[contains(@id,'verificationMsg')]
or 要么
//*[ends-with(@id,'verificationMsg')]
you can use CSS identifier as well. 您也可以使用CSS标识符。 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. 您可以使用xpath的ends-with方法。 Something like below example- 像下面的例子-
WebElement cls=ff.findElement(By.xpath("//*[ends-with(@id,'verificationMsg')]"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.