VietTuts

Tự Học Lập Trình Online

  • Home
  • Java
  • Servlet
  • JSP
  • Struts2
  • Hibernate
  • Spring
  • MyBatis
  • Java WS
  • C
  • C++
  • Python
  • PHP
  • Eclipse
  • VBA
  • Web
    • JavaScript
    • JQUERY
    • JSON
    • AJAX
    • CSS
    • HTML
  • SQL
    • MySQL
    • SQL Server
  • Misc
    • Phần mềm tiện ích
    • Selenium Test
  • Tuyển Dụng

Học Selenium - Automation Test

Kiểm thử tự động là gì? Automation Testing Selenium là gì? Các lệnh trong Selenium IDE – “Selenese” Giới thiệu Selenium Webdriver Selenium WebDriver Locators – xác định vị trí phần tử HTML

Tương Tác Người Dùng

Tương tác người dùng Tương tác Text Box Tương tác Radio Button Tương tác Check Box Tương tác Drop Down Ví dụ kéo thả trong Selenium Thao tác bàn phím Thao tác chuột Chọn nhiều hạng mục Tìm tất cả Link

Selenium WebDriver Nâng Cao

Page Object Model (POM) Selenium WebDriver Page Factory trong Selenium WebDriver XPath trong Selenium WebDriver Inject JQuery trong Selenium WebDriver

Chọn nhiều hạng mục trong Selenium


Mouse actions trong Selenium
Tìm tất cả các Link trong Selenium

Đôi khi bạn sẽ gặp tình huống phải để chọn hai hoặc nhiều hạng mục trong một list box hoặc text are.

Bài này sẽ sử dụng trang web https://demos.devexpress.com/aspxeditorsdemos/ListEditors/ MultiSelect.aspx để thực hiện chọn nhiều hạng mục trong Selenium.


Ví dụ

Trong ví dụ này, chúng ta sẽ chon 3 hạng mục trong list 'Phone features' như hình sau:

Ví dụ Chọn nhiều hạng mục trong Selenium

File: MultiSelectDemo.java

package vn.viettuts.selenium;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class MultiSelectDemo {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", 
                "D:\\SeleniumWebdriver\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        // Open website
        driver.get("http://demos.devexpress.com/aspxeditorsdemos"
                + "/ListEditors/MultiSelect.aspx");
        
        // Maximize the browser
        driver.manage().window().maximize();
        
        // set 'Selection mode' to Multiple
        driver.findElement(
                By.id("ControlOptionsTopHolder_lbSelectionMode_B-1Img"))
                .click();
        driver.findElement(
                By.id("ControlOptionsTopHolder_lbSelectionMode_DDD_L_LBI1T0"))
                .click();
        Thread.sleep(5000);
        
        // Perform Multiple Select
        Actions builder = new Actions(driver);
        WebElement select = driver.findElement(
                By.id("ContentHolder_lbFeatures_LBT"));
        List<WebElement> options = select.findElements(By.tagName("td"));
        Action multipleSelect = builder.keyDown(Keys.CONTROL) // Ctrl Key
                .click(options.get(0)) // 3G
                .click(options.get(3)) // Memory Card Slot 
                .click(options.get(5)) // Touch Screen
                .build();
        multipleSelect.perform();
        System.out.println("Mutil Select: ");
        System.out.println(options.get(0).getText());
        System.out.println(options.get(3).getText());
        System.out.println(options.get(5).getText());
        
        // driver.close();
    }
}

Kết quả:

Mutil Select: 
3G
Memory Card Slot
Touch screen

Mouse actions trong Selenium
Tìm tất cả các Link trong Selenium

Recent Updates

Bài tập Python có lời giảiHọc Lập Trình Online Miễn Phí - VietTuts.VnPhân biệt List, Tuple, Set, Dictionary trong PythonHàm Dictionary dict() trong PythonHàm Set set() trong PythonBài tập Java - Trộn 2 mảng trong javaBài tập Java - Chèn phần tử vào mảng trong javaBài tập Java - Sắp xếp mảng theo thứ tự giảm dầnBài tập Java - Sắp xếp mảng theo thứ tự tăng dầnJava - Liệt kê số lần xuất hiện của các phần tử trong một mảngJava - Liệt kê các phần tử xuất hiện trong mảng đúng 2 lầnJava - Liệt kê các phần tử xuất hiện trong mảng đúng 1 lần

VietTuts on facebook

Học Lập Trình Online Miễn Phí - VietTuts.Vn

Danh sách bài học

Học java
Học servlet
Học jsp
Học Hibernate
Học Struts2
Học Spring
Học SQL

Câu hỏi phỏng vấn

201 câu hỏi phỏng vấn java
25 câu hỏi phỏng vấn servlet
75 câu hỏi phỏng vấn jsp
52 câu hỏi phỏng vấn Hibernate
70 câu hỏi phỏng vấn Spring
57 câu hỏi phỏng vấn SQL

About VietTuts.Vn

Hệ thống bài học trên VietTuts.Vn bao gồm các bài lý thuyết và thực hành về các công nghệ java và công nghệ web. Các bài lý thuyết trên hệ thống VietTuts.Vn được tham khảo và tổng hợp từ các trang http://javatpoint.com, http://www.tutorialspoint.com, http://docs.oracle.com/en …

Scroll back to top

Copyright © 2016 VietTuts.Vn all rights reserved. | VietTuts.Vn team | Liên hệ | Chính sách - riêng tư | sitemap.html | sitemap_index.xml