0

I need to click a radio button, but the page does not respond

I use the following: myField = driver.FindElement(By.Id("payment:payRadio:0")); myField.Click();

I get the following error "element not interactable" I assume I need someway to execute javascript

<input id="payment:payRadio:0" name="payment:payRadio" type="radio" value="1" onchange="PrimeFaces.ab({s:&quot;payment:payRadio&quot;,e:&quot;valueChange&quot;,f:&quot;payment&quot;,p:&quot;payment:payRadio&quot;,u:&quot;payment:payOptions&quot;});" />

What do I need to do to fire up the onchange event?

Deek880
  • 29
  • 3
  • `driver.executescript()` is about right. possibly `execute_script` depending on your underlying language. This method lets you run JS in the browser. You can either interact with your element with `driver.executescript('arguments[0].click()', myField)` or you can try and run that js directly since it seems to be in your element: `driver.executescript('PrimeFaces.ab({s:"payment:payRadio",e:"valueChange",f:"payment",p:"payment:payRadio",u:"payment:payOptions"});')` – RichEdwards Oct 24 '22 at 08:30
  • I'm using C#. It says driver does not contain a definition for executescript – Deek880 Oct 25 '22 at 15:11
  • Good news is it does exist. C# just needs a little bit more faff. Have a read here https://stackoverflow.com/questions/6229769/execute-javascript-using-selenium-webdriver-in-c-sharp – RichEdwards Oct 26 '22 at 16:47
  • Thanks so much for your help. I made a few changes and it works now! – Deek880 Oct 27 '22 at 01:00
  • myField = driver.FindElement(By.Name("payment:payRadio")); // https://stackoverflow.com/questions/74175906/how-can-i-make-selenium-executed-an-onchange-event-on-a-webpage?noredirect=1#comment130966984_74175906 IJavaScriptExecutor jsDriver = driver as IJavaScriptExecutor; jsDriver.Equals(myField); jsDriver.ExecuteScript("arguments[0].click()", myField); – Deek880 Oct 27 '22 at 01:00

0 Answers0