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(); } }
Benefits of using HtmlUnitDriver??
ReplyDeleteAnd it will not pop browser instead it will run in the background. so majorly HtmlUnitDriver is used for Load Testing.
Delete