水豚:是否有可能从CSS字符串中获取属性值? [英] Capybara: is it possible to get an attribute value from a css string?

查看:51
本文介绍了水豚:是否有可能从CSS字符串中获取属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一些HTML,例如:

If I've got some HTML like:

<div id='drawer'><ul><li><a href='www'>description</a>...

我已经看到我可以通过以下方式在Capybara中获得href的值:

I've seen that I can get the value of href in Capybara with:

page.find('div#drawer a')['href']

但是,如果将其完全描述为CSS字符串?即,尝试获取'div#drawer a [href]'的值

But is there any way to retrieve that value if it's completely described as a css string? ie, trying to get the value for 'div#drawer a[href]'

我尝试过这样的表达式:

I've tried with expressions like this:

page.find('div#drawer a[href]')        => can't convert Capybara::Node::Element into String (TypeError)
page.find('div#drawer a[href]').value  => can't convert nil into String (TypeError)
page.find('div#drawer a[href]').text   => returns the text value of 'description'

我已经在外部配置文件中找到了css表达式,

I've got that css expression in an external config file, so would it be possible somehow to just use it directly and retrieve the value of the attribute in question?

谢谢...

推荐答案

可能为时已晚。但是我也遇到了同样的问题,并找到了解决方案。

Probably too late. But I also had the same problem and found the solution. It might help someone else.

page.find('div#drawer a')[:href]

这篇关于水豚:是否有可能从CSS字符串中获取属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆