Sunday, 17 December 2023

Selenium 4.16.1 boiler plate code

public WebDriver driver; public ChromeOptions co;


public static void main(String[] args) {

    co = new ChromeOptions();

    driver = new ChromeDriver(co);

    driver.get("https://google.com");

    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

    driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));

    driver.findElement(By.name("q")).sendKeys("Automation Step by Step");

    driver.findElement(By.name("q")).sendKeys(Keys.ENTER);

    driver.close();

    driver.quit();

}



Quick Tips :

// to press enter key

driver.findElement(By.name("q")).sendKeys(Keys.ENTER);


// to find any keyword on the webpage

driver.getPageSource().contains("Online Courses");



No comments:

Post a Comment