Category Archives: Selenium

Check or Click In Selenium?

Selenium is a wonderful tool that allows scripting using a browser. Note that this is different from scripting in the browser. Essentially, it offers apis in multiple different languages (perl, java, ruby and python) to open a browser, and do all tasks that one could manually do such as filling in the fields, clicking links, submitting forms etc all done programatically.

One of the form controls is a radio button. Selenium offers apis to select a radio button. This function is called check where you can pass the element locator of the radio button to be selected. There is also a function called click to which one can pass a clickable element locator. My usecase was to select a radio button that’s not the default when the page was loaded. So, I simply used the check function and ran the selenium script but the result wasn’t as expected. It turned out that using click instead of the check function solved the problem. Can you take a guess why that was the case? Hint: It’s not a fault with Selenium.

The reason is that the radio button had some onclick javascript. The check api will not bother to generate a onclick event because, there is no click happening there. So, by using the click command, I managed to both change the radio button and also make the browser execute the javascript code that the application required to be executed.

2 Comments

Filed under Selenium