Showing posts with label CheckBox handling with Selenium. Show all posts
Showing posts with label CheckBox handling with Selenium. Show all posts

Run a Bat File with Java Program


Sample JAVA Code:

public class RunBat {

public static void main(String[] args) throws IOException, InterruptedException{

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c F:\\bb.bat");
process.waitFor();
}
}

What is the difference between absolute and relative Xpath?


Absolute Xpath : 

1) start selection from the document node
2) Starts with //
3) e.g. “/html/body/p” matches all the paragraph elements

Google Search Box : /html/body/div[1]/div[2]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div

Relative Xpath  : 

1) start selection matching anywhere in the document
2) Starts with /
3) e.g. “//p” matches all the paragraph elements starts with p

Google Search Box : //*[@id='gbqfqwb']

How to Automate CheckBox/RadioButton Using Selenium WebDriver

 

// How to automate CheckBox/RadioButton

 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 public class CheckBox {  
      public static void main(String[] args) throws InterruptedException {  
           WebDriver driver = new FirefoxDriver();  
           String Url = "https://www.facebook.com/";  
           driver.get(Url);  
           Boolean select = driver.findElement(By.xpath("//*[@id='persist_box']")).isSelected();  
           if (select == false)  
           {  
                driver.findElement(By.xpath("//*[@id='persist_box']")).click();  
           }  
           Thread.sleep(5000);  
 driver.close();            
      }  
 }