How to handle a checkbox on a webpage and check its state using Selenium Webdriver

0 votes
How to handle a checkbox on a webpage and check its state using Selenium Webdriver?
May 14, 2019 in Selenium by Chris
3,005 views

1 answer to this question.

0 votes

Hey Chris, to handle a checkbox and check its status using Selenium Webdriver, follow these steps:

1. Launch the Eclipse IDE and right click on the src folder and then click on the New > class. Enter the class name as Checkbox_test:

Handling Checkbox

 

2. Now, invoke the Google Chrome browser by setting the system property to the path of your chromedriver.exe file:

System.setProperty("webdriver.chrome.driver","C:\\\\work\\\\chromedriver.exe);
WebDriver driver = new ChromeDriver(); 

3. Next, navigate to the SpiceJet website:

driver.navigate().to("https://www.spicejet.com/");  

4. Then try to locate the 'Senior Citizen' checkbox by inspecting its HTML code:

5. Write the code that will locate 'Senior Citizen' checkbox and check whether its checked or not by using these line of code:

System.out.println(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());
driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).click();  
System.out.println(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());

6. Finally, click on Run button to execute the automation. You would see this result in your Console:

answered May 14, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to check all checkboxes on a webpage using Selenium?

Hey Jenny, to check all the checkboxes ...READ MORE

answered Jun 26, 2019 in Selenium by Suraj
5,209 views
0 votes
1 answer

How to get all options of a dropdown on a webpage using Selenium Webdriver?

Hey Joel, you can use following lines ...READ MORE

answered Jul 15, 2019 in Selenium by Abha
• 28,140 points
2,519 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer

How to automate radio button and checkbox on a webpage in Selenium Webdriver?

Hey Yashmita, following code snippet automates the ...READ MORE

answered Jul 23, 2019 in Selenium by Anvi
• 14,150 points
2,352 views
0 votes
1 answer

How to handle checkboxes on a webpage using Ruby Selenium Webdriver?

Hi Sandeep, you can use following code ...READ MORE

answered Aug 26, 2019 in Selenium by Anvi
• 14,150 points
2,141 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP