Automating Seckill Price Setup in Admin UI with Selenium Java

This article provides a detailed Java Selenium script that navigates a backend admin list, locates a specific course by ID, handles pagination and status checks, and programmatically sets the flash‑sale price using JavaScript interactions.

FunTester
FunTester
FunTester
Automating Seckill Price Setup in Admin UI with Selenium Java

When using Selenium for testing, sometimes you need to configure test data in a backend management interface that is on a different page from the course details. This article shares a representative Java script that locates a course in a list page and sets its seckill (flash sale) price.

First, the page layout and relevant XML snippet are shown (image). Then the main method setSeckillPriceByCourseId(int courseId, int price) is presented, which navigates to the course list, selects the formal course, and calls findCourseByIdAndSetSeckillPrice to perform the actual setting.

The helper method findCourseByIdAndSetSeckillPrice(int courseId, int price) iterates through paginated course listings, searches for the element whose data-course_id matches the target ID, and handles different status cases:

When the status is "开始秒杀" (start flash sale), it scrolls to the element, clicks via JavaScript, inputs the new price, confirms, and waits for a success message before returning a status code 2.

If the status is "结束秒杀" (sale already started), it logs the condition and returns status 3.

If the course is not found after two pages, it returns status 4.

The method returns integer codes: 1 – course found, 2 – price set successfully, 3 – sale already started, 4 – course not found.

Supporting utility methods for JavaScript interaction are also provided:

public void scrollToElement(WebElement element) {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].scrollIntoView(true);", element);
}
public void clickByJs(WebElement element) {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", element);
}

These snippets demonstrate a practical approach to automate backend configuration tasks with Selenium, handling dynamic elements, pagination, and JavaScript‑driven interactions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendjavaautomationtestingWebUISelenium
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.