javascript - 如何存储链接的ID? [英] javascript - how to store the id of a link?
本文介绍了javascript - 如何存储链接的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用selenium IDE获取,存储和使用记录的ID。
html是
< span class ='small'>< a href =/ users / change_district / 31>(选择)< / a>< ; /跨度>
我想获得 31
部分并将其存储在变量myVar中
我正在阅读的关于selenium的建议是用javascript做的,即有
store | javascript {...} |我的问题是: {...}
javascript代码是什么?解决方案您可以使用XPath和JavaScript的组合来实现这一目标。像这样:
storeAttribute | // * [@ class ='small'] / a [text()='(选择)'] / @ href | hrefAttr
store | javascript {storedVars ['hrefAttr']。replace(/.* \ //,'')} | myVar
echo | $ {myVar}
输出:
31
I'm trying to use the selenium IDE to get, store and use the id of a record.
The html is
<span class='small'><a href="/users/change_district/31">(Select)</a></span>
I want to get the 31
part of that and store it in variable myVar
The advice I am reading for selenium says to do it with javascript, i.e. have
store | javascript{...} | myVar
My question is: what should the {...}
javascript code be?
解决方案 You could use a combination of XPath and JavaScript to get that. Like this:
storeAttribute | //*[@class='small']/a[text()='(Select)']/@href | hrefAttr
store | javascript{storedVars['hrefAttr'].replace(/.*\//,'')} | myVar
echo | ${myVar}
Output:
31
这篇关于javascript - 如何存储链接的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文