❅
❅
❆
❅
❆
❅
❆
❅
❆
❆

  • 0939206009
  • thaian.it15@gmail.com
  • Facebook
  • Youtube
  • Zalo
Anh Tester Logo
  • Khoá học
    • All Courses
    • Website Testing
    • API Testing
    • Desktop Testing
    • Mobile Testing
    • Programming Language
    • CI/CD for Tester
    • Performance Testing
  • 💥Khai giảng
  • tools
    • TestGenAI - AI Test Cases Generator
    • Mobile Apps Demo
    • Automation Framework Selenium TestNG
    • Automation Framework Cucumber TestNG
    • Gherkin Convert Functions in Katalon
    • Convert object from Selenium Java to Playwright Python
    • Website Demo CRM
    • Website Demo HRM
    • Website Demo HRM GO
    • Website Demo POS
    • Website Demo eCommerce CMS
  • blog
    • Selenium C#
    • Selenium Java
    • Katalon Tools
    • Jenkins CI/CD
    • SQL cho Tester
    • Manual Testing
    • Tài liệu cho Tester
    • Automation Testing
    • akaAT Tools
    • Cucumber TestNG
    • API Testing with Postman
    • Apache Maven
    • AI in Software Testing
    • Lịch khai giảng
  • Liên hệ
  • Log in
    Sign up

[Selenium C#] [Bài 2] - Thực hành thao tác với Element

  • Blog
  • Automation Testing
[Selenium C#] [Bài 2] - Thực hành thao tác với Element

[Selenium C#] [Bài 2] - Thực hành thao tác với Element

  • Anh Tester
  • Automation Testing
  • 3325
Selenium C# Bài 2 sẽ giới thiệu đến các bạn các cách lấy Element và thực hành thao tác với chúng trong Selenium C#.

Ví dụ 1: Nhấp vào liên kết bằng XPATH Locator:

Kịch bản thử nghiệm:

1. Điều hướng đến trang web Demo - https://demoqa.com/
2. Phóng to cửa sổ Chrome
3. Nhấp vào menu "Element"

Demo Page
 4. Nhấp vào menu "Text Box"
 Text box

Code mẫu:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VTACourses.PageObjects;

namespace VTACourses
{
    class SeleniumDemo
    {
        IWebDriver driver;


        [SetUp]
        public void startBrowser()
        {
            driver = new ChromeDriver("D:\\TESTER\\Automation Testing\\Project"); //Thư mục cuối cùng chứa File Chromedriver.exe
            driver.Manage().Window.Maximize(); //Để bung fullscreen màn hình cái Chrome
        }


        [Test]
        public void DemoGetElement()
        {
            driver.Url = "https://demoqa.com/";
            Thread.Sleep(3000);

            IWebElement moduleElement = driver.FindElement(By.XPath("//*[name()='path' and contains(@d,'M16 132h41')]"));
            moduleElement.Click();
            Thread.Sleep(2000);
            IWebElement menuTextBox = driver.FindElement(By.XPath("//span[contains(text(),'Text Box')]"));
            menuTextBox.Click();
            Thread.Sleep(2000);
        }​


        [TearDown]
        public void closeBrowser()
        {
            driver.Close();
        }
    }
}

Ví dụ 2: Nhập dữ liệu vào TextBox và nhấp vào nút Submit bằng cách sử dụng bộ định vị ID:

Kịch bản thử nghiệm:

  1. Tại vị trí của Ví dụ 1 chúng ta tiếp tục
  2. Nhập dữ liệu vào các ô Input
  3. Bấm vào nút "Submit"
  4. Check thông tin bên dưới
- Name
- Email
- Current Address
- Permananet Address

Text Input

Code mẫu:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VTACourses.PageObjects;

namespace VTACourses
{
    class SeleniumDemo
    {
        IWebDriver driver;


        [SetUp]
        public void startBrowser()
        {
            driver = new ChromeDriver("D:\\TESTER\\Automation Testing\\Project"); //Thư mục cuối cùng chứa File Chromedriver.exe
            driver.Manage().Window.Maximize(); //Để bung fullscreen màn hình cái Chrome
        }


        [Test]
        public void DemoGetElement()
        {
            driver.Url = "https://demoqa.com/";
            Thread.Sleep(5000);
            IWebElement moduleElement = driver.FindElement(By.XPath("//*[name()='path' and contains(@d,'M16 132h41')]"));
            moduleElement.Click();
            Thread.Sleep(2000);
            IWebElement menuTextBox = driver.FindElement(By.XPath("//span[contains(text(),'Text Box')]"));
            menuTextBox.Click();
            Thread.Sleep(2000);

            //SendKeys (Nhập liệu)
            IWebElement txtFullName = driver.FindElement(By.Id("userName"));
            IWebElement txtEmail = driver.FindElement(By.Id("userEmail"));
            IWebElement txtCurentAddress = driver.FindElement(By.Id("currentAddress"));
            IWebElement txtPermanentAddress = driver.FindElement(By.Id("permanentAddress"));
            //Click (Button)
            IWebElement btnSubmit = driver.FindElement(By.Id("submit"));

            txtFullName.SendKeys("VTA Courses");
            Thread.Sleep(1000);
            txtEmail.SendKeys("abc@email.com");
            Thread.Sleep(1000);
            txtCurentAddress.SendKeys("Đồng Tháp");
            Thread.Sleep(1000);
            txtPermanentAddress.SendKeys("Cần Thơ");
            Thread.Sleep(1000);
            btnSubmit.Click();
            Thread.Sleep(3000);
        }


        [TearDown]
        public void closeBrowser()
        {
            driver.Close();
        }
    }
}

  • Tags:
  • Selenium C#
  • Bài 2
  • Selenium
  • Automation Test

Chia sẻ bài viết

Facebook Linkedin Telegram Pinterest Share with Zalo Zalo

Cộng đồng Automation Testing Việt Nam

🌱 Facebook Fanpage: Anh Tester
🌱 Telegram
Automation Testing:   Cộng đồng Automation Testing
🌱 
Facebook Group Automation: Cộng đồng Automation Testing Việt Nam
🌱 Telegram
Manual Testing:   Cộng đồng Manual Testing
🌱 
Facebook Group Manual: Cộng đồng Manual Testing Việt Nam

  • Anh Tester

    Anh Tester

    Đường dẫu khó chân vẫn cần bước đi
    Đời dẫu khổ tâm vẫn cần nghĩ thấu

    • Facebook
    • Youtube
    • Zalo

Search Blogs

Related Blogs

🤖 So sánh Playwright JS/TS và Playwright Python

🤖 So sánh Playwright JS/TS và Playwright Python

Aug-29-2025 by Anh Tester
So sánh Playwright và Selenium trong Test Automation

So sánh Playwright và Selenium trong Test Automation

Aug-23-2025 by Anh Tester
🚀 Lộ trình học Automation Tester tại Anh Tester

🚀 Lộ trình học Automation Tester tại Anh Tester

Aug-23-2025 by Anh Tester
Những kỹ năng cần có cho level Senior Automation Tester

Những kỹ năng cần có cho level Senior Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Middle Automation Tester

Những kỹ năng cần có cho level Middle Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Junior Automation Tester

Những kỹ năng cần có cho level Junior Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Fresher Automation Tester

Những kỹ năng cần có cho level Fresher Automation Tester

Dec-17-2024 by Anh Tester
Cách xử lý các Exceptions trong Selenium WebDriver

Cách xử lý các Exceptions trong Selenium WebDriver

May-31-2024 by Anh Tester
Tại sao chúng ta cần Kiểm thử Tự động

Tại sao chúng ta cần Kiểm thử Tự động

May-30-2024 by Anh Tester
How to get HTML5 validation message with Selenium

How to get HTML5 validation message with Selenium

Mar-22-2024 by Anh Tester
view all

Blog Tags

  • Selenium
  • Xpath
  • Locator
  • Jenkins
  • Testing
  • Tester
  • Thuật ngữ
  • Lộ trình
  • Khóa học
  • Mindset
  • QA
  • QC
  • Checklist
  • Website
  • Mobile
  • Question
  • Answer
  • Phỏng vấn
  • Extension
  • Cucumber
  • Gherkin
  • Agile
  • Scrum
  • Document
  • Testing Level
  • Automation Test
  • Test Cases
  • Trường hợp
  • Katalon
  • JMeter
  • Postman
  • API
  • Manual Test
  • Developer

Anh Tester

Anh Tester profile
Đường dẫu khó chân vẫn cần bước đi
Đời dẫu khổ tâm vẫn cần nghĩ thấu

Connect me on

  • Facebook
  • Youtube
  • Zalo


Liên hệ

  • 0939206009
  • thaian.it15@gmail.com
  • Anh Tester
  • Donate for Anh Tester
QR Facebook Group
QR Discord Group

Copyright © 2021-2025 Anh Tester Automation Testing