Hey @Shushil, you can run your test scripts using PhantomJS browser in Selenium with following code snippet:
package headlessDriver;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class PhantomDriver {
public static void main(String[] args) {
File file = new File("C:/Program Files/phantomjs-2.0.0-windows/bin/phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Edureka");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
Once you run this code, you will observe the output is shown in your Console and no browser is launched: