我正在 try catch 将随机生成的元素的 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 |
我怎么能做到这一点?
最佳答案
Selenium 中有两个选项,XPath 和 CSS 选择器。我读过 CSS Selector 更适合在 FireFox 和 IE 中进行测试。
使用最新版本的 Selenium IDE(2009 年 3 月 5 日),我成功地使用了评估 Javascript 表达式的 storeEval,让您可以访问 javascript 字符串函数。
XPath:
storeAttribute | //div[1]@id | divID
storeEval | '${divID}'.replace("divElement-", "") | number
type | //tr[@id='form-${number}']/td/form/fieldset/p[1]/input | Type this
CSS 选择器:
storeAttribute | css=div[1]@id | divID
storeEval | '${divID}'.replace("divElement-", "") | number
type | css=tr[id='form-${number}'] > td > form > fieldset > p[1] > input | Type this
关于regex - 如何仅捕获 id 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/401905/