File tree Expand file tree Collapse file tree 5 files changed +96
-1
lines changed
src/test/java/com/anhtester
Bai8_Checkbox_Radio_Dropdown Expand file tree Collapse file tree 5 files changed +96
-1
lines changed Original file line number Diff line number Diff line change 19
19
<dependency >
20
20
<groupId >org.seleniumhq.selenium</groupId >
21
21
<artifactId >selenium-java</artifactId >
22
- <version >4.10 .0</version >
22
+ <version >4.11 .0</version >
23
23
</dependency >
24
24
25
25
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ public class BaseTest {
11
11
12
12
public static WebDriver driver ;
13
13
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
+
14
22
public static void createBrowser (){
15
23
//Khởi tạo Browser
16
24
driver = new ChromeDriver ();
You can’t perform that action at this time.
0 commit comments