Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testing-modules/selenium-3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

<properties>
<testng.version>7.10.2</testng.version>
<selenium-java.version>4.27.0</selenium-java.version>
<webdrivermanager.version>5.9.2</webdrivermanager.version>
<selenium-java.version>4.38.0</selenium-java.version>
<webdrivermanager.version>6.3.3</webdrivermanager.version>

</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.baeldung.selenium.autocomplete;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import java.time.Duration;
import java.util.List;

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.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class AutoCompleteLiveTest {

private static final String XPATH_INPUT = "//div[@id='gh-search-box']//input";
private static final String XPATH_AUTOCOMPLETE_ITEMS = "//ul[@id='ebay-autocomplete']/li";

private WebDriver driver;

@BeforeEach
void setup() {
driver = new ChromeDriver();
}

@AfterEach
void teardown() {
driver.quit();
}

@Test
void whenUserNavigatesToEBays_thenSelectThe2ndAutoCompleteItemFromSearchInput() throws Exception {
driver.navigate().to("https://www.ebay.com");

WebElement inputElement = driver.findElement(By.xpath(XPATH_INPUT));
String text = "iphone";
for (char c : text.toCharArray()) {
inputElement.sendKeys(Character.toString(c));
Thread.sleep(50);
}

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
List<WebElement> autoCompleteElements = wait.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(
By.xpath(XPATH_AUTOCOMPLETE_ITEMS)
)
);

assertThat(autoCompleteElements.size()).isGreaterThanOrEqualTo(2);

WebElement secondItem = autoCompleteElements.get(1);
secondItem.click();
}

}