【问题标题】:Accessing a Syncfusion Dropdown through Selenium Unit Tests通过 Selenium 单元测试访问 Syncfusion 下拉菜单
【发布时间】:2023-01-26 23:54:21
【问题描述】:

在我的单元测试中,我试图断言用户可以访问并从下拉菜单中选择一个项目。我已经构建了我能做的每个.FindElement() 扩展,但是在运行单元测试时它找不到下拉菜单。谁能帮我弄清楚如何选择它?下拉项列表来自代码库中别处构建的列表。

@Syncfusion下拉列表代码

<SfDropDownList TItem="Industry" TValue="string" Placeholder="Select..." PopupHeight="20px" DataSource="@Industries" AllowFiltering="true" @bind-Value="Industry" ID="industry">
    <DropDownListEvents TItem="Industry" TValue="string" ValueChange="@(ChangeIndustry)"></DropDownListEvents>
    <DropDownListFieldSettings Text="IndustryName"></DropDownListFieldSettings>
</SfDropDownList>

@测试

var industry = driver.FindElement(By.Id("industry"));
var selectElement = new SelectElement(industry);
selectElement.SelectByText("Construction");

//Assert
Assert.Contains("Construction", industry.Text);

【问题讨论】:

  • 请为下拉菜单添加从浏览器生成的 HTML。

标签: c# selenium selenium-webdriver syncfusion


【解决方案1】:

SelectElement 类仅适用于 SELECT HTML 元素,不能在此处使用。您必须单击该元素以打开下拉列表,然后根据使用 XPath 包含的文本找到所需的元素。您还没有提供在浏览器中为下拉菜单生成的 HTML,因此我无法提供具体的定位器,但这应该能让您大致了解。

var industry = driver.FindElement(By.Id("industry"));
industry.click(); // open the dropdown
driver.FindElement(By.XPath("???")).click();

【讨论】:

  • 嗨,杰夫,感谢您的回复。这让我错过了一步更有意义。你的意思是让我提供浏览器的图片吗?由于 Syncfusion 组件被包装在单个 div 中,然后 Syncfusion 组件位于该 div 中。
猜你喜欢
  • 1970-01-01
  • 2015-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
相关资源
最近更新 更多