13 Replies Last post: Mar 30, 2007 12:50 PM by tintu  
Beginner 22 posts since
Mar 27, 2007
Currently Being Moderated

Mar 27, 2007 10:38 AM

Select the ids of radio buttons in a page using selenium

Is it possible to select the ids of radio buttons in a page using selenium..?

Is there any method that will does this function..?

Anyone knowing please help...

R Pro 230 posts since
Feb 9, 2007
Currently Being Moderated
1. Mar 28, 2007 12:33 AM in response to: tintu
Re: Select the ids of radio buttons in a page using selenium

click | //input[contains(@id,'_id3:0')]

Konstantin Petkov Guru 634 posts since
Jan 1, 2007
Currently Being Moderated
3. Mar 28, 2007 5:07 AM in response to: tintu
Re: Select the ids of radio buttons in a page using selenium

No, there is no such function, but you may easy create such, based on the getAllButtons implementation:

 

BrowserBot.prototype.getAllButtons = function() {

    var elements = this.getDocument().getElementsByTagName('input');

    var result = '';

 

    for (var i = 0; i < elements.length; i++) {

        if (elements.type == 'button' || elements.type == 'submit' || elements+.type == 'reset') {

            result = elements.id;

 

            result += ',';

        }

    }

 

    return result;

};

 

To get the radio buttons, you need to check for type='radio' instead.

Konstantin Petkov Guru 634 posts since
Jan 1, 2007
Currently Being Moderated
5. Mar 28, 2007 8:54 AM in response to: tintu
Re: Select the ids of radio buttons in a page using selenium

Sure.

This function is an already available one - it is used when you call the method returning all the button ids. So you need to extend Selenium (read about extending the code here:

http://www.openqa.org/selenium-core/reference.html]

 

with an additional function (getAllRadioButtons for example), which checks about "radio" type of the elements (as I posted above) and then call the respective method in your Java test case.

 

Message was edited by: konstantin.petkov

Konstantin Petkov Guru 634 posts since
Jan 1, 2007
Currently Being Moderated
8. Mar 29, 2007 7:10 AM in response to: tintu
Re: Select the ids of radio buttons in a page using selenium

Unfortunately I don't know the answer and haven't seen the error you posted above so far. Why don't you post your question in Selenium RC forum, where more people working with the remote control will be able to see the problem?

 

http://forums.openqa.org/forum.jspa?forumID=13

 

Sorry for not being able to help you further.

R Pro 230 posts since
Feb 9, 2007
Currently Being Moderated
10. Mar 30, 2007 4:05 AM in response to: tintu
Re: Select the ids of radio buttons in a page using selenium

I've tried next code in the user-extensions.js : (using Selenium Core)

 

BrowserBot.prototype.getAllRadios = function() {

    var elements = this.getDocument().getElementsByTagName('input');

    var result = '';

 

    for (var i = 0; i < elements.length; i++) {

        if (elements+.type == 'radio') {

            result = elements.id;

 

            result += ',';

        }

    }

 

    return result;

};

 

but using command:

 

storeAllRadios | rad1 |

 

returns error:

 

Unknown command: 'storeAllRadios'

 

 

why this happens?

Konstantin Petkov Guru 634 posts since
Jan 1, 2007
Currently Being Moderated
11. Mar 30, 2007 4:15 AM in response to: R
Re: Select the ids of radio buttons in a page using selenium

I guess you need to define the command in selenium-api.js as well. Just call the one from browserbot there.

R Pro 230 posts since
Feb 9, 2007
Currently Being Moderated
12. Mar 30, 2007 5:25 AM in response to: Konstantin Petkov
Re: Select the ids of radio buttons in a page using selenium

thx! it works fine

 

have changed selenium-api.js

have added function to the selenium-browserbot.js - do not know why user-extensions.js do not work for me

More Like This

  • Retrieving data ...