0

I am calling a function twice to execute a piece of code in my protractor script. A snapshot of the code of my function that is failing when called the second time is below. sessionNo is an argument passed to this function. It could be either 0 or 1. Depending on the value of this argument, either the radio button with index 0 will be selected or the radio button with index 1 will be selected.

function sessionBegin(sessionNo)
{
    element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).isPresent(). then(function()
    {
        var sessionType = element.all(by.repeater('type in types')).all(by.css ("input[type='radio']")).get(sessionNo);
        sessionType.click();                                             
    });
}

This code works great when this function is called for the first time. But when it is called the second time with a different value for sessionNo, it fails with "Failed: element not visible" error. I can't figure out why is the above code unable to locate the same element for the second time as it did for the first time with the exact same code.

Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
SoniaS
  • 13
  • 1
  • 4

1 Answers1

0

It depends on your application code, may be your element becomes invisible between it's found and click action, or it's not visible yet. For the first case you should investigate what happens in application side, for second case (if it's not visible yet), you can wait until it became visible, for example: browser.wait(EC.visibilityOf(element), 5000, Element not visible: ${element.locator()}); it will wait for for element 5 seconds.

Niyarlatotep
  • 71
  • 1
  • 10
  • Thank you. I already tried this, but it didn't help. I tried a couple of suggestions that are listed here by @alecxe to make the radio button visible, but nothing worked. https://stackoverflow.com/questions/37809915/element-not-visible-error-not-able-to-click-an-element – SoniaS May 25 '17 at 16:06