Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a radio button element by value using Selenium?

Until now I just did like:

val radioButton4: WebElement = driver.findElement(By.id("FieldsubCode2"))

radioButton4.click

but now I want to find element by value, this value:

enter image description here

So I want to go:

val radioButton4: WebElement = driver.findElement(By.value("3.2"))


radioButton4.click

How can I do that?

like image 660
Joe Avatar asked Dec 21 '15 13:12

Joe


People also ask

How you will identify if a radio button is selected in Selenium?

How to verify that if the Radio Button is selected using Selenium isSelected() method? Once we ran this code, the code will first check if the radio button is selected or not. Then an if condition will validate if the returned value is true or false. In case if it is false, i.e., the radio button is not selected.

How does xpath select radio button in Selenium?

xpath("//input [@name='group1']")). size(); The above line of code calculates the number of radio buttons whose name is group1. Now, we will handle the radio buttons by using the index of a particular radio button.

How do I find radio buttons?

We can find a radio button element by value with Selenium webdriver. A radio button in an html document has a tagname input and it has a type attribute set to radio. We can select a radio button by using the click() method after identifying it. Let us see the html code of a radio button.


1 Answers

If you want to find only by value then use,

driver.findElement(By.xpath("//input[@value='3.2']"));
like image 115
Bharat DEVre Avatar answered Dec 31 '22 13:12

Bharat DEVre