General webpage functionality : Verify radio button is clickable

Language: Java

Framework: Selenium 4

copy
1Assumptions:2- The webpage has at least one radio button element.3- The radio button element is visible and enabled.4- The radio button element is not currently in a disabled or read-only state.56/​/​ Import Selenium 4 libraries7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.By;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.remote.RemoteWebDriver;13import java.net.URL;1415public class GeneralFunctionalityTest {16 public static void main(String[] args) {1718 /​/​ Set up local Chrome driver19 System.setProperty("webdriver.chrome.driver", "path/​to/​chromedriver");20 WebDriver driver = new ChromeDriver();2122 /​/​ Commented code for connecting to remote client with desired capabilities23 /​* DesiredCapabilities capabilities = DesiredCapabilities.chrome();24 /​/​ Set desired capabilities here25 WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capabilities); */​2627 /​/​ Navigate to webpage28 driver.get("https:/​/​example.com");2930 /​/​ Click radio button element31 WebElement radioButton = driver.findElement(By.id("radio-button-id"));32 radioButton.click();3334 /​/​ Check if radio button is currently selected35 if (!radioButton.isSelected()) {36 System.out.println("Radio button was not successfully clicked.");37 }3839 /​/​ Close the browser40 driver.quit();41 }42}

Language: Python

Framework: Selenium 4

copy
1from selenium import webdriver23#Assuming local driver location4driver = webdriver.Chrome('path/​to/​chromedriver')56#Assuming webpage URL7url = "https:/​/​example.com"89#Assuming radio button element id10radio_id = "radio_button"1112#Opening webpage in browser13driver.get(url)1415#Assuming radio button is initially unchecked16assert not driver.find_element_by_id(radio_id).is_selected()1718#Clicking on radio button19driver.find_element_by_id(radio_id).click()2021#Asserting that radio button is checked after clicking22assert driver.find_element_by_id(radio_id).is_selected()2324#Assuming remote client's desired capabilities25remote_url = "http:/​/​127.0.0.1:4444/​wd/​hub"26desired_capabilities = webdriver.DesiredCapabilities.CHROME.copy()2728#Connecting to remote client with desired capabilities29remote_driver = webdriver.Remote(remote_url, desired_capabilities)

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing