views:

30

answers:

2

I am trying to run an if statement in selenium that would verify if a checkbox was checked and if it was not perform a certain action. I tried

if (selenium.verifyChecked("checkbox")=false){
//perform actions
} else {
//perform different actions
};

and it said that that did not work. How would you do it?

+2  A: 
if (selenium.verifyChecked("checkbox")=false){

Is wrong. It's assigning false to the return value of the function, which is clearly wrong.

It should be:

if (selenium.verifyChecked("checkbox") == false) {
Not Joe Bloggs
o ok, would not this work also: if (!selenium.verifyChecked("checkbox")) {
chromedude
@chromedude: Yes
Not Joe Bloggs
+2  A: 

The Selenium command isChecked returns a boolean, so you should be able to do the following:

if (selenium.isChecked("checked")) {
  //perform actions
} else {
  //perform different actions
};
Dave Hunt
thanks. That is what I found out about and have ended up using. So much better than try - catch and verifyChecked();
chromedude