Angularjs 无法选择下拉列表值

Angularjs 无法选择下拉列表值,angularjs,selenium-webdriver,automated-tests,ui-automation,Angularjs,Selenium Webdriver,Automated Tests,Ui Automation,我试图从下拉列表中选择值,但得到的错误元素本应为select,但为mat select。我正在测试angularjs应用程序,我能够成功地选择下拉列表。但当我尝试在下拉列表中选择值时,我会出错 以下是我用于从下拉列表中选择元素的方法: public void clickandselectstoregroup(){ WebElement storegroupIDdropdown = WebDriverUtils.getWebDriver().findElement(By.id(ma

我试图从下拉列表中选择值,但得到的错误元素本应为select,但为mat select。我正在测试angularjs应用程序,我能够成功地选择下拉列表。但当我尝试在下拉列表中选择值时,我会出错

以下是我用于从下拉列表中选择元素的方法:

public void clickandselectstoregroup(){
        WebElement storegroupIDdropdown = WebDriverUtils.getWebDriver().findElement(By.id(matselectStoreGroup));
        Select se = new Select(storegroupIDdropdown);
        se.selectByIndex(1);

    }
错误日志:

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "mat-select"
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
System info: host: '', ip: '127.0.0.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.Select.<init>(Select.java:47)
    at com.morrisons.automation.pageobjects.sma.SchedulePageObject.clickandselectstoregroup(SchedulePageObject.java:225)
    at com.morrisons.automation.stepdefs.sma.NewScheduleStepDef.i_select_storegroup_dropdown_and_select_dropdown_value(NewScheduleStepDef.java:98)
    at ?.And I select storegroup dropdown and select dropdown value(C:/AutomationNeon1/atom/src/main/features/smascheduler/new-schedule.feature:22)

看起来AngularJS没有选择元素。它有另一个特性,WebDriver不能使用您的web元素,如Select

我还没有测试AngularJS

不过,我可以建议一个解决方案,在这种情况下,只使用本地点击。您需要单击替换选择功能:

第一个用于打开下拉列表 第二,选择正确的列表元素。 代码段应类似于:

DriverUtils.getWaiter().until(ExpectedConditions.elementToBeClickable(By.id("vchannel_combobox"))).click();
DriverUtils.getWaiter().until(ExpectedConditions.elementToBeClickable(By.xpath(
  String.format("//Rectangle[@id='vchannel_drop_down']/ListView/Item/Item[%d]", RandomUtils.nextInt(1, 4))))
).click();
在下面的示例中,您可以看到两个适当的操作。在这种情况下,选择哪个元素无关紧要。
从列表中选择正确的元素时,使用了Xpath定位器。

错误说明了一切:

Element should have been "select" but was "mat-select"
很明显,WebElement StoreGroupId下拉列表被标识为:

WebDriverUtils.getWebDriver().findElement(By.id(matselectStoreGroup));
此WebElement未在任何..中定义。。。。。标签相反,它是在。。。。。标签

因此,当您尝试调用selectByIndexn方法时,只需当前对象无法调用该方法,selectByIndexn方法即可由SelectType对象调用。因此,您可以看到错误

解决方案:
如果您仔细查看HTML DOM,您可能会发现。。。。。标签或a。。。。。。。控制下拉列表的标记。您需要识别这些问题并与之合作。

您的问题解决了吗?