selenium is not able to identify radiobutton -
driver.get("http://www.quackit.com/html/codes/html_radio_button.cfm"); list<webelement> radio_button = driver.findelements(by.name("preferred_color")); system.out.println(radio_button.get(0).getattribute("value")); system.out.println(radio_button.get(0).getattribute("checked")); radio_button.get(0).click(); //check radio button if unchecked system.out.println(radio_button.get(0).getattribute("checked"));
this error getting :-
starting chromedriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 29374 local connections allowed. exception in thread "main" java.lang.indexoutofboundsexception: index: 0, size: 0 @ java.util.arraylist.rangecheck(unknown source) @ java.util.arraylist.get(unknown source) @ test.main(test.java:27)
your radio buttons inside iframe
name result1
, need switch iframe
first go find radio elements :-
driver.switchto().frame("result1");
full code :-
driver.get("http://www.quackit.com/html/codes/html_radio_button.cfm"); driver.switchto().frame("result1"); list<webelement> radio_buttons = driver.findelements(by.name("preferred_color")); system.out.println(radio_buttons.size()); if(radio_buttons.size() > 0) { webelement radio_button = radio_buttons.get(0); system.out.println(radio_button.getattribute("value")); system.out.println(radio_button.isselected()); if(!radio_button.isselected()) { ((javascriptexecutor)driver).executescript("arguments[0].click()", radio_button); //check radio button if unchecked } system.out.println(radio_button.isselected()); }
hope helps..:)
Comments
Post a Comment