Skip to content

Commit 5a7bec1

Browse files
committed
Bài 8 - Checkbox Radio Dropdown
1 parent fcb69d1 commit 5a7bec1

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>org.seleniumhq.selenium</groupId>
2121
<artifactId>selenium-java</artifactId>
22-
<version>4.10.0</version>
22+
<version>4.11.0</version>
2323
</dependency>
2424

2525
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.anhtester.Bai8_Checkbox_Radio_Dropdown;
2+
3+
import com.anhtester.Bai5_Locators.BT_Locators.LocatorsCRM;
4+
import com.anhtester.common.BaseTest;
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.Keys;
7+
8+
public class DemoAddCustomer extends BaseTest {
9+
public static void main(String[] args) {
10+
createBrowser();
11+
driver.get("https://crm.anhtester.com/admin/authentication");
12+
sleep(1);
13+
driver.findElement(By.xpath(LocatorsCRM.inputEmail)).sendKeys("admin@example.com");
14+
driver.findElement(By.xpath(LocatorsCRM.inputPassword)).sendKeys("123456");
15+
driver.findElement(By.xpath(LocatorsCRM.buttonLogin)).click();
16+
sleep(1);
17+
driver.findElement(By.xpath(LocatorsCRM.menuCustomers)).click();
18+
sleep(1);
19+
driver.findElement(By.xpath(LocatorsCRM.buttonAddNewCustomer)).click();
20+
//Chọn Group
21+
sleep(1);
22+
driver.findElement(By.xpath(LocatorsCRM.dropdownGroups)).click();
23+
sleep(1);
24+
String groupName = "VIP";
25+
driver.findElement(By.xpath(LocatorsCRM.inputSearchGroups)).sendKeys(groupName);
26+
//Click chọn item group hoặc nhấn ENTER
27+
//driver.findElement(By.xpath(LocatorsCRM.inputSearchGroups)).sendKeys(Keys.ENTER);
28+
driver.findElement(By.xpath("//span[normalize-space()='" + groupName + "']")).click();
29+
sleep(1);
30+
driver.findElement(By.xpath(LocatorsCRM.dropdownGroups)).click();
31+
32+
closeBrowser();
33+
}
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.anhtester.Bai8_Checkbox_Radio_Dropdown;
2+
3+
import com.anhtester.common.BaseTest;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.Keys;
6+
7+
public class HandleDropdownDynamic extends BaseTest {
8+
public static void main(String[] args) {
9+
createBrowser();
10+
11+
driver.get("https://techydevs.com/demos/themes/html/listhub-demo/listhub/index.html");
12+
sleep(2);
13+
//Click vào dropdown Category
14+
driver.findElement(By.xpath("//span[normalize-space()='Select a Category']")).click();
15+
//Search giá trị cần chọn
16+
sleep(1);
17+
driver.findElement(By.xpath("//span[normalize-space()='Select a Category']/parent::a/following-sibling::div//input")).sendKeys("Travel");
18+
//Click chọn Text đã search (cần chọn)
19+
sleep(1);
20+
//driver.findElement(By.xpath("//li[@class='active-result highlighted']")).click();
21+
driver.findElement(By.xpath("//span[normalize-space()='Select a Category']/parent::a/following-sibling::div//input")).sendKeys(Keys.ENTER);
22+
23+
closeBrowser();
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.anhtester.Bai8_Checkbox_Radio_Dropdown;
2+
3+
import com.anhtester.common.BaseTest;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.support.ui.Select;
6+
7+
public class HandleDropdownStatic extends BaseTest {
8+
public static void main(String[] args) {
9+
createBrowser();
10+
11+
driver.get("http://demo.seleniumeasy.com/basic-select-dropdown-demo.html");
12+
sleep(1);
13+
//Khởi tạo đối tượng của class Select
14+
Select select = new Select(driver.findElement(By.xpath("//select[@id='select-demo']")));
15+
16+
//Chọn option theo 3 hàm hỗ trợ
17+
select.selectByVisibleText("Monday");
18+
sleep(1);
19+
select.selectByValue("Tuesday");
20+
sleep(1);
21+
select.selectByIndex(5); //Vị trí thứ 6 (bắt đầu từ 0)
22+
23+
//Kiểm tra giá trị đã chọn đúng chưa
24+
System.out.println(select.getFirstSelectedOption().getText());
25+
26+
closeBrowser();
27+
}
28+
}

src/test/java/com/anhtester/common/BaseTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ public class BaseTest {
1111

1212
public static WebDriver driver;
1313

14+
public static void sleep(double second){
15+
try {
16+
Thread.sleep((long) (1000*second));
17+
} catch (InterruptedException e) {
18+
throw new RuntimeException(e);
19+
}
20+
}
21+
1422
public static void createBrowser(){
1523
//Khởi tạo Browser
1624
driver = new ChromeDriver();

0 commit comments

Comments
 (0)