- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the total number of radio buttons on a page using Selenium?
We can get the total number of radio buttons on a page using Selenium webdriver using the find_elements method. While working on any radio buttons, we will always find an attribute type in the html code and its value should be radio.
This characteristic is only applicable to radio buttons on that particular page and to no other types of UI elements like edit box, link, and so on.
To retrieve all the elements with attribute type = 'radio', we will use find_elements_by_xpath() method. This method returns a list of web elements with the type of xpath specified in the method argument. In case there are no matching elements, an empty list will be returned.
After the list of radio buttons is fetched, in order to count its total numbers, we need to get the size of that list. The size of the list can be obtained from the len() method of the list data structure.
Finally, this length is printed on the console.
Code Implementation for counting radio buttons.
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm") #to refresh the browser driver.refresh() # identifying the radio buttons with type attribute in a list chk =driver.find_elements_by_xpath("//input[@type='radio']") # len method is used to get the size of that list print(len(chk)) #to close the browser driver.close()
- How to count the total number of radio buttons in a page in Selenium with python?
- How to get the total number of checkboxes in a page using Selenium?
- How to count the total number of links in a page in Selenium?
- How to count the total number of tables in a page in Selenium with python?
- How to get content of entire page using Selenium?
- C# program to get the total number of cores on a computer
- How to select a radio button in a page in Selenium with python?
- Minimum number of page turns to get to a desired page using C++.
- How to count the number of frames in a page in Selenium?
- How to get the complete screenshot of a page in Selenium with python?
- How to count the total number of links in Selenium with python?
- How to count the total number of frames in Selenium with python?
- Get page title with Selenium WebDriver using Java.