【发布时间】:2016-01-19 09:18:29
【问题描述】:
我有代码可以很好地为我检索静态文本元素,但我想要做的是将该元素的 xpath 作为字符串获取。我正在使用红宝石。此时,我有一个已经检索到的元素数组。以下是我尝试过但没有运气的方法。
elements.each do |element|
if element.attribute("name").include? vProblem
p "Problem found, retrieving xpath..."
# Neither of these work
p "Problem xpath is: " + element.attribute("xpath").to_s
p "Problem xpath is: " + element.xpath.to_s
end
end
【问题讨论】:
-
我不相信有办法,因为有无限可能的 xpath。此外,您已经从 if 语句中的信息中知道了 xpath,例如
//*[@name='vProblem'](在元素内)