admin管理员组

文章数量:1402924

I have found the product name ID and checked that it's neither hidden nor missing. However, when I call the function to retrieve the ID, it says the ID cannot be found. Are there any ways to fix this or alternative solutions?

[Test]
public void Themsanphamhople()
{
    LoginAdmin("thien", "123456");

    // Chuyển đến trang danh sách sản phẩm
    driver.Navigate().GoToUrl("http://localhost:8838/Admin/Product/Index");

    try
    {
        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        IWebElement btnThem = wait.Until(drv => drv.FindElement(By.Id("btn-themsanpham")));
        btnThem.Click();

        IWebElement tenSanPham = driver.FindElement(By.Name("TENSP"));
        tenSanPham.SendKeys("Harry porter");
    }
    catch (WebDriverTimeoutException ex)
    {
        Assert.Fail($"Lỗi khi chạy test: {ex.Message}");
    }
}

The ID is inside a form, and I have already checked that it is neither duplicated nor hidden and I have tried all types of find element methods.

本文标签: selenium webdriverHow to test a form in an ASPNET MVC web applicationStack Overflow