java - How to check a radio button with Selenium WebDriver? -
i want check radio button, didn't know how. html is:
<div class="appendcontent"> <div> id="contentcontainer" class="grid_list_template"> <div id="routemonitoroptions"></div> </div> <input id="optionstopgrid" type="radio" name="gridselector"/> <label for="optionstopgrid">paradas</label> </div>
import java.util.list; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.firefox.firefoxdriver; public class answer { public static void main(string[] args) throws interruptedexception { webdriver driver = new firefoxdriver(); driver.get("http://www.example.com/"); //if u want know number of radio buttons use list list<webelement>radiobutton = driver.findelements(by.tagname("example")); system.out.println(radiobutton.size()); //if u want select radio button driver.findelement(by.id("example")).click(); thread.sleep(3000); //if u want text in u r console for(int i=0;i<radiobutton.size();i++){ system.out.println(radiobutton.get(i).gettext()); } //if u want check whether radio button selected or not if(driver.findelement(by.id("example")).isselected()){ system.out.println("true"); }else { system.out.println("false"); } } }
Comments
Post a Comment