Forum: Ruby Selenium webdriver CSS attribute reading

249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-19 08:51
I have the below kind HTML :


<input type="submit" name="btnAddRequest" value="Add Bizz1"
onclick="validSubmit=true;document.forms[0].elements['fieldViewerId'].value
= 12676701;" class="btnSmall">
<input type="submit" name="btnAddRequest" value="Update Bizz1"
onclick="validSubmit=true;document.forms[0].elements['fieldViewerId'].value
= 12676701;" class="btnSmall">
<input type="submit" name="btnAddRequest" value="Add Bizz2"
onclick="validSubmit=true;document.forms[0].elements['fieldViewerId'].value
= 12676701;" class="btnSmall">

I am using selenium-webdriver.

driver.find_elements(:name,"btnAddRequest")

- giving all the three of the above. But I want to `click` only one the
one having value as `Update Bizz1` . How to perform such test any idea?
There are 100 buttons like this. I just pasted three of them.
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-03-19 09:57
I don't think selenium webdriver allows for selection on multiple
criteria the way watir webdriver does.
You'd probably have to do something like this:

driver.find_elements(:name,"btnAddRequest").select {|el| el.name ==
"btnAddRequest" }.first.click

It seems unnecessarily long-winded to me. Watir-webdriver is much
simpler to use.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-19 10:41
@Joel - thanks for your interest, But I managed it as below:



driver.find_elements(:name,"btnAddRequest").each{ |elem|

if elem.attribute(:value) == 'Add Bizz2' then

#print elem.attribute(:value)
elem.click
break

end

}
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-03-22 10:04
FYI, this is the watir-webdriver equivalent. Much simpler, shorter, and
more readable.

driver.button({name: 'btnAddRequest', value: 'Add Bizz2'}).click
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-25 17:47
Humm,

I will definitely look into the `watir-webdriver` anyways. :)

Let me first grasp the whole logic of selenium-webdriver,then I will
taste it.

Thanks
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.