如何仅捕获 id 的一部分?
我正在尝试捕获将随机生成的元素的 id。 我可以像这样成功捕获元素 id 的值...
| storeAttribute | //div[1]@id | variableName |
现在我的变量将类似于...
divElement-12345
我想删除“divElement-”,以便剩下的变量是“12345”,以便我可以使用稍后选择与之关联的“form-12345”元素...类似这样:
| type | //tr[@id='form-${variableName}']/td/form/fieldset/p[1]/input | Type this |
我如何才能完成此任务?
I'm trying to capture the id of an element that will be randomly generated. I can successfully capture the value of my element id like this...
| storeAttribute | //div[1]@id | variableName |
Now my variable will be something like...
divElement-12345
I want to remove 'divElement-' so that the variable I am left with is '12345' so that I can use it later to select the 'form-12345' element associated with it...something like this:
| type | //tr[@id='form-${variableName}']/td/form/fieldset/p[1]/input | Type this |
How might I be able to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XPATH 中有很多函数可以解决您的问题。 假设“divElement-”是一个不会改变的常量,并且您使用的是 XPath 2.0,我建议:
substring-after(div[1]/@id/text(),"divElement-")
There are many functions in XPATH which should solve your problem. Assuming "divElement-" is a constant that will not change and that you are using XPath 2.0, I would suggest:
substring-after(div[1]/@id/text(),"divElement-")
Selenium 有两个选项:XPath 和 CSS 选择器。 我读过 CSS 选择器更适合在 FireFox 和 IE 中进行测试。
使用最新版本的 Selenium IDE(2009 年 3 月 5 日),我成功地使用了 storeEval 来计算 Javascript 表达式,使您可以访问 javascript 字符串函数。
XPath:
CSS 选择器:
You have two options in Selenium, XPath and CSS Selector. I have read that CSS Selector is better for doing tests in both FireFox and IE.
Using the latest version of Selenium IDE (3/5/2009) I've had success with using storeEval which evaluates Javascript expressions, giving you access to javascript string functions.
XPath:
CSS Selector: