Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract attribute values using css selectors?

I want to select the values of attributes of an element. e.g If I have an input element

<input type="text" name=myInput value="100">

I can locate it using input[name='myInput'], but how do I get the value of it using a css selector?

BTW, I am trying to do this in Selenium using css selectors

like image 669
John Avatar asked Dec 29 '09 01:12

John


2 Answers

You might want to explain what you're trying to do with the value. For instance, I have the following CSS to display the text of the links in the '#content' element in my print style sheet:

#content a:link:after, #content  a:visited:after {
    content: " (" attr(href) ") ";
    font-size: 90%;
}

#content a[href^="/"]:after {
    content: " (http://example.com" attr(href) ") ";
}
like image 109
Joe Avatar answered Oct 17 '22 00:10

Joe


If in Perl using WWW::Selenium then it's simply:

my $val = $selenium->get_value("css=input[name='myInput']");

If using another language then the Selenium library should support a get_value function/method.

like image 45
slebetman Avatar answered Oct 17 '22 01:10

slebetman