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"));
Asked
Active
Viewed 69 times
-1

undetected Selenium
- 183,867
- 41
- 278
- 352
-
Error pointing at WebElement line – saikiran thotakura Sep 10 '19 at 11:29
-
And the error is? post full stack trace. – Guy Sep 10 '19 at 11:31
-
@saikiranthotakura check that elements with id `email` or name `passwd` are actually present/visible – bhusak Sep 10 '19 at 11:34
-
@bhusak Yes there are elements with id email and name passwd – saikiran thotakura Sep 10 '19 at 11:42
-
@Guy the error is pointing at WebElement line and at id – saikiran thotakura Sep 10 '19 at 11:45
-
@saikiranthotakura I didn't ask *where* it is, I asked *what* it is. – Guy Sep 10 '19 at 11:46
-
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String baseUrl = "http://demo.guru99.com/test/login.html"; driver.get(baseUrl); WebElement email = driver.findElement(By.id("email")); WebElement password = driver.findElement(By.name("passwd")); – saikiran thotakura Sep 10 '19 at 11:47
1 Answers
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:

undetected Selenium
- 183,867
- 41
- 278
- 352
-
The same error is what i got when i used .id also, help me out – saikiran thotakura Sep 10 '19 at 11:56
-
@saikiranthotakura Checkout the updated answer and let me know the status. – undetected Selenium Sep 10 '19 at 12:11
-
after updating Error: The method cssSelector(String) is undefined for the type By – saikiran thotakura Sep 10 '19 at 12:16
-
-
-