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 in Selenium by Chris
79 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 by Anvi
• 13,400 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

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,090 points
773 views
0 votes
1 answer
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,130 points
1,018 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
722 views
0 votes
1 answer
0 votes
1 answer