Friday, March 27, 2020

How to handle Radio button and Checkbox 



import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class VerifyCheckbox {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("file:///D:/Ingenious_TechHub_Teaching/Ingenious_Selenium/Htmldoc/checkbox.html");
    driver.manage().window().maximize();
    WebElement chbox=driver.findElement(By.xpath("//input[@id='vehicle1']"));
    chbox.click();
   boolean checkboxsle= chbox.isSelected();
   if(checkboxsle){
   System.out.println("checkboxsle...selected" + checkboxsle);
   }
   else{
   System.out.println("checkboxsle...not selected" + checkboxsle);
   }
    
    
    
}

}


=======================================================================
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class verifyRadiobutton {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("file:///D:/Ingenious_TechHub_Teaching/Ingenious_Selenium/Htmldoc/radio.html");
driver.manage().window().maximize();
WebElement radioele= driver.findElement(By.xpath("//input[@value='male']"));
radioele.click();
boolean radielesel= radioele.isSelected();
if(radielesel){
System.out.println("Male radio button is selected");
}
else{
System.out.println("Male radio button is not selected");
}

}

}
========================================================================
package com.seleniumpract;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class VerifyCheckbox {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("file:///D:/Ingenious_TechHub_Teaching/Ingenious_Selenium/Htmldoc/checkbox.html");
    driver.manage().window().maximize();
    WebElement chbox=driver.findElement(By.xpath("//input[@id='vehicle1']"));
    chbox.click();
   boolean checkboxsle= chbox.isSelected();
   if(checkboxsle){
   System.out.println("checkboxsle...selected" + checkboxsle);
   }
   else{
   System.out.println("checkboxsle...not selected" + checkboxsle);
   }
    
    
    
}

}


How to automate checkbox

Show Checkboxes





Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...