ruby - Add Nokogiri parse result to variable -


i have xml document:

<cred> <login>tove</login> <pass>jani</pass> </cred> 

my code is:

require 'nokogiri' require 'selwet'  context "parse xml" doc = nokogiri::xml(file.open("test.xml")) doc.xpath("cred/login").each  |char_element|  puts char_element.text  end  should "check" unit.go_to "http://www.ya.ru/" unit.click '.b-inline' unit.fill '[name="login"]', @login end 

when run test get:

 tove  0 

but want insert parse result @login. how can variables parsing result? need insert login , pass values xml fields in web page?

i'd use values:

require 'nokogiri'  doc = nokogiri::xml(<<eot) <cred> <login>tove</login> <pass>jani</pass> </cred> eot  login = doc.at('login').text # => "tove" pass = doc.at('pass').text # => "jani" 

nokogiri makes easy access values using css, use readability when possible. same thing can done using xpath:

login = doc.at('//login').text # => "tove" pass = doc.at('//pass').text # => "jani" 

but having add // twice accomplish same thing wasted effort.

the important part at, returns first occurrence of target. at allows use either css or xpath, css less visually noisy.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -