首页 > 解决方案 > 我正在自动化一个角度注册表单,我有一个下拉框,其 id 是 span 以及如何根据用户输入选择选项

问题描述

这是我的代码:

WebElement id1=driver.findElement(By.cssSelector(".mat-select-placeholder"));
Select drid = new Select(id1);
drid.selectByIndex(1);

我得到错误元素被选择但它是跨度的。

如何解决这个问题?

HTML:

<mat-form-field id="select-shyam"> <mat-label>Favorite food</mat-label> <mat-select id="select-parth"> <mat-option *ngFor="let food of foods; let index = index" [value]="food.value" id="{{'select-parth-' + index}}"> {{food.viewValue}} </mat-option> </mat-select> </mat-form-field> <br> <br> 

错误 :

org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应该是“select”但是“mat-select”构建信息:版本:'3.10.0',修订:'176b4a9',时间:'2018-03- 02T19:10:56.039Z' 系统信息:主机:'GTJPCPU07',ip:'192.168.40.160',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java .version: '1.8.0_161' 驱动程序信息: driver.version: org.openqa.selenium.support.ui.Select.(Select.java:47) at EtaCore.Setup_Clear_Roles.addnewwrole(Setup_Clear_Roles.java:118) 未知sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)

标签: angularjsselenium-webdriver

解决方案


推荐阅读