The text is in the div, not linked to the checkboxes. Looks like poorly
organised html.
If you know the value you want, then you could do this (examples given
in watir-webdriver, which you REALLY need to start using for the sake of
your own sanity):
driver.checkbox(:value => ‘9556609’).set
If you have to work out which of the div’s text rows goes with which
checkbox you’d probably have to do it via indices. Extracting the div’s
text didn’t take the newlines so I had to split by spaces.
my_div = driver.div(:id => ‘filtersetedit_fieldNames’)
name_array = my_div.text.split
name_array.each_with_index do |name, idx|
puts “name: #{name} value: #{my_div.checkbox(:index, idx).value}”
end
output:
name: John value: 5418630
name: Ram value: 6360899
name: Smith value: 9556609
name: Paul value: 20156687
Once you have the names and corresponding values you can set whichever
one you like.
The text is in the div, not linked to the checkboxes. Looks like poorly
organised html.
If you know the value you want, then you could do this (examples given
in watir-webdriver, which you REALLY need to start using for the sake of
your own sanity):
driver.checkbox(:value => ‘9556609’).set
If you have to work out which of the div’s text rows goes with which
checkbox you’d probably have to do it via indices. Extracting the div’s
text didn’t take the newlines so I had to split by spaces.
The DIV, not the Checkbox, contains the Name you want; so each
“x.text” will be blank.
Watir-Webdriver contains Selenium-Webdriver. Switching to it is
simple and it was specifically made to make writing browser-automating
code easier for you. I see no reason to persist in using the more
difficult selenium API when there’s a layer already designed to help
Rubyists use it more effectively. Use the open-source tools that
selfless people have expended great effort to make.
See this (especially the illustrative image): Home - Watir-Melon
Do your own research first! There are several ways to do what you
want here, and when you completely fail to take in the information
provided, and ask questions which have already been answered, you will
find less and less help being offered to you.
This:
driver.find_elements(:id,“filtersetedit_fieldNames”).each do |x|
Will give you only 1 result. That’s not a loop. Read my example more
carefully.
If you’re getting spaces within individual names, you’ll need to extract
the html from the Div and parse that using Regex to find the appropriate
checkbox name.
Here is an example of the Regex required to find the checkbox value for
“Joh Das”
I don’t have watir-web driver installed in my PC. Now so I am trying to
understand it by logic.
name_array= [John,Ram,Smith,Paul] If it really this,then I think my one
should also work for me:
Now I tried the code as below against the HTML below:
Joh
Das Ram Roy Smith Paul
Code:
driver.find_elements(:id,“filtersetedit_fieldNames”).each do |x|
puts x.text #puts index
break if x.text == “LocationAttributes:Currency Type”
index = index + 1
end
Google. Google. Google. Seriously, how difficult is it to type in
“Regex” into Google? I really feel like you are way over your head with
what you are trying to do, and you’re using this forum/mailing list as
your personal team of programmers. I’m not normally one to speak out
like this, but I have only been here for about a month and have watched
you spam the list with constant questions about language and programming
fundamentals in general. Pick up a good book on Ruby. Pick up a good
book on programming. No, I won’t recommend any (Google). If, after
reading and trying your best to figure stuff out on your own, you still
have questions, then by all means ask the list.
Joel, I commend you for your constant help with this person, but you’re
basically being used as a free programmer.
Google. Google. Google. Seriously, how difficult is it to type in
“Regex” into Google? I really feel like you are way over your head with
what you are trying to do, and you’re using this forum/mailing list as
I don’t know why you made such “harsh” comment. Is this forum not for a
newbie? And If you think that I am using this to drive my team, really
you are - not to say…
Joel, I commend you for your constant help with this person, but you’re
basically being used as a free programmer.
Thanks
The best way to learn is to teach. I’m very new at this myself, so I’m
basically building up my own skillset by doing this kind of thing.
I agree with the overall sentiment as well: You shouldn’t ask other
people until exhausting your own avenues of investigation.
Joel, I commend you for your constant help with this person, but you’re
basically being used as a free programmer.
Thanks
The best way to learn is to teach. I’m very new at this myself, so I’m
basically building up my own skillset by doing this kind of thing.
I agree with the overall sentiment as well: You shouldn’t ask other
people until exhausting your own avenues of investigation.
Thank you very much :)@joel. Please don’t think I am using you for my
sake,but I am taking help from you to gap of my knowledge.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.