BAEL-6194 Retrieve the Value of an HTML Input Using Selenium WebDriver in Java (#13898)

* Retrieve the Value of an HTML Input Using Selenium WebDriver in Java

* Retrieve the Value of an HTML Input Using Selenium WebDriver in Java

* Retrieve the Value of an HTML Input Using Selenium WebDriver in Java
This commit is contained in:
Michael Olayemi 2023-04-30 03:40:16 +01:00 committed by GitHub
parent 141df4e0ff
commit 1770c64f3a
2 changed files with 45 additions and 2 deletions

View File

@ -57,9 +57,9 @@
<properties>
<testng.version>6.10</testng.version>
<selenium-java.version>4.6.0</selenium-java.version>
<selenium-java.version>4.8.3</selenium-java.version>
<ashot.version>1.5.4</ashot.version>
<webdrivermanager.version>5.3.0</webdrivermanager.version>
<webdrivermanager.version>5.3.2</webdrivermanager.version>
</properties>
</project>

View File

@ -0,0 +1,43 @@
package com.baeldung.selenium.webdriver;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class SeleniumWebDriverUnitTest {
private WebDriver driver;
private static final String URL = "https://duckduckgo.com/";
private static final String INPUT_ID = "search_form_input_homepage";
@BeforeEach
public void setUp() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
@AfterEach
public void tearDown() {
driver.quit();
}
@Test
public void givenDuckDuckGoHomePage_whenInputHelloWorld_thenInputValueIsHelloWorld() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.id(INPUT_ID));
inputElement.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.DELETE);
inputElement.sendKeys("Hello World!");
String inputValue = inputElement.getAttribute("value");
Assert.assertEquals("Hello World!", inputValue);
}
}