Step 1. vào https://www.adayroi.com, in ra title của trang chủ
Step 2. tìm kiếm từ khóa điện thoại
Step 3. chọn sắp xếp theo Bán chạy nhất
Step 4. chụp ảnh màn hình để xem lại kết quả
Dưới đây là code của bài tập này
/*
https://haibgit.blogspot.com/
Test Steps
Step 1. vào https://www.adayroi.com, in ra title của trang chủ
Step 2. tìm kiếm từ khóa điện thoại
Step 3. chọn sắp xếp theo Bán chạy nhất
Step 4. chụp ảnh màn hình để xem lại kết quả
*/
package BaiTap;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.apache.commons.io.FileUtils;
public class Ngay1 {
public static void main(String[] args) throws IOException {
String url = "https://www.adayroi.com";
WebDriver driver = new ChromeDriver();
driver.get(url);
System.out.println(driver.getTitle());
//nhập từ khóa điện thoại và ô tìm kiếm
driver.findElement(By.id("header__main__segment_search__form__input")).sendKeys("điện thoại");
//sau đó click tìm kiếm
driver.findElement(By.id("header__main__segment_search__form__submit")).click();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
//tìm menu dropdown sắp xếp
driver.findElement(By.id("products_list_order_by_container")).click();
//click vào bán chạy nhất
driver.findElement(By.id("a_order_1")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//chụp ảnh màn hình để xem kết quả
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String png = ("C:\\Ngay1\\sap xep" + ".png");
FileUtils.copyFile(scrFile, new File(png));
//đóng trình duyệt
driver.close();
}
}
Sau đây chúng ta hãy nhìn hình ảnh lưu trong C:\Ngay1Hẹn gặp các bạn ở các bài tiếp theo!

0 comments:
Post a Comment