-1
String baseUrl = "http://demo.guru99.com/test/login.html";  
driver.get(baseUrl);

// Get the WebElement corresponding to the Email Address(TextField) 
WebElement email = driver.findElement(By.id("email"));

// Get the WebElement corresponding to the Password Field       
WebElement password = driver.findElement(By.name("passwd"));                            
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

1 Answers1

0

To send the credentials within the Email address and Password field you can use the following Locator Strategies:

  • Code Block:

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class A_demo 
    {
        public static void main(String[] args) throws Exception 
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
            options.setExperimentalOption("useAutomationExtension", false);
            WebDriver driver = new ChromeDriver(options);
            driver.get("http://demo.guru99.com/test/login.html");
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#email"))).sendKeys("saikiran_thotakura");
            driver.findElement(By.cssSelector("input#passwd")).sendKeys("saikiran_thotakura");
        }
    }
    
  • Browser Snapshot:

guru99

DebanjanB
  • 118,661
  • 30
  • 168
  • 217