Selenium webdriver: how to say if radioobox / checkbox is checked

I am using Selenium web editor with javascript and node.js

At some point in my test, I must check (approve) if a specific radio box has already been verified.

I want to check if it is checked, which means that my test will be successful.

I actually tried to do this:

  var radioInput = driver.findElement(webdriver.By.xpath('//*[@id="radio1'));
  radioInput.isSelected().then(function() {
    done();
  });

I do not know, but it does not work.

suggestions

+4
source share
3 answers

I solve it as follows:

var element = driver.findElement(webdriver.By.xpath('//*[@id="radioID"]'));

element.getAttribute("checked").then(function(value) {
  assert.equal(value, 'true');
  //traitement
});
0
source

Try instead to var radioInput = driver.findElement(webdriver.By.xpath('//*[@id="radio1')); use driver.wait(until.elementIsVisible(driver.findElement(By.and so on.

0
source

isSelected , if/else,

            var radioInput = driver.findElement(webdriver.By.xpath('//*[@id="radio1'));
            var state = radioInput.isSelected();
            if(state)
            {
                //THINGS TO DO IF RADIO IS ON
            }
            else
            {
                //THINGS TO DO IF RADIO IS OFF
            }
0

Source: https://habr.com/ru/post/1676661/


All Articles