Tuesday, July 18, 2017

Headless Driver

https://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html


package  htmldriver;
import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver;  
public class htmlUnitYest {    
  public static void main(String[] args) {
                     // Creating a new instance of the HTML unit driver
                      
                     WebDriver driver = new HtmlUnitDriver();   //could use any browser here
                //And it will not pop browser instead it will run in the background. so majorly HtmlUnitDriver is used for Load Testing.      
                  // Navigate to Google  
                     driver.get("http://www.google.com");     
          
      // Locate the searchbox using its name  
                     WebElement element = driver.findElement(By.name("q")); 
                     
                    // Enter a search query  
                    element.sendKeys("Guru99"); 
                   
              // Submit the query. Webdriver searches for the form using the text input element automatically  
                    // No need to locate/find the submit button  
                    element.submit();   
                    
              // This code will print the page title  
                    System.out.println("Page title is: " + driver.getTitle());  
                    
                    driver.quit();   
         }  
} 

2 comments:

  1. Replies
    1. And it will not pop browser instead it will run in the background. so majorly HtmlUnitDriver is used for Load Testing.

      Delete