0% found this document useful (0 votes)
11 views1 page

Bai 2 - Search Element

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Bai 2 - Search Element

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

[email protected].

vn

Bài 2: Test search


Find web element
Bước 1: Thêm mới 1 phương thức Test

@Test
public void testSearch() {
// Open Google
driver.get("https://www.google.com");

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

// Wait for the search box to be present


WebElement searchText = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));

searchText.sendKeys("dai hoc fpt da nang");

// Wait for the search button to be clickable and then click it


WebElement googleSearchButton =
wait.until(ExpectedConditions.elementToBeClickable(By.name("btnK")));
googleSearchButton.click();

// Wait for the search results page to load


wait.until(ExpectedConditions.titleContains("fpt da nang"));

// Assert that the title contains the search term


String title = driver.getTitle();
assertTrue(title.contains("fpt da nang"));
}

Một số lưu ý:

 WebDriverWait: nên được sử dụng để chờ element xuất hiện, tránh dung Thread.sleep

You might also like