Reputation: 315
I am trying to extract a value displayed in an element(drop down box) on a webpage using xpaths. I have firebug and xpath checker installed in firefox and the element I am trying to extract from looks like such:
<input id="dateTxt" class="textBox" value="Thursday June 20" onfocus="this.blur()" onclick="gird.show('date')" size="9" maxlength="50" readonly="readonly">
Apologies I am not allowed to share exactly what I'm working with but that is the jist.
I want to save the ontents of value ( value = "Thursday June 20" ) to a string so I can parse for the date. But I have not been able to get the xpath correct. This is what I have so far as in my code
text = @driver.find_element(:xpath => "//*[@id=\"dateTxt\"]")
If I perform .text on this nothing is assigned to text.
If more information is needed please request it, this is my first day working with xpaths.
Upvotes: 1
Views: 1695
Reputation: 118271
Humm.. You can try the below :
@driver.find_element(:css,"input#dateTxt").attribute("value")
#=> "Thursday June 20"
@driver.find_element(:xpath,"//input[@id = 'dateTxt']").attribute("value")
#=> "Thursday June 20"
Look at the below page Element examples:
and Selenium::WebDriver::Element#attribute
Upvotes: 2