我有一个月下拉列表,默认情况下会 Select 下拉列表中显示的所有月份.问题是,我只希望2050-Jan个月复选框保持选中状态,并希望另一个月复选框保持选中状态.请注意,年份和月份是动态的.i、 e.如果下拉菜单显示3个选项,则同一下拉菜单可以显示2个选项,也可以显示3个以上的选项.

在这种情况下,我如何取消选中其他两个或更多复选框.

在Java selenium中自动化任何潜在客户都将非常有用.

现在,如果你看到下面的下拉菜单有3个月和一年的默认 Select ,我只需要2050-Jan保持未选中状态.

这是一个动态的下拉列表,年份和月份将发生变化,但2050年1月将始终存在,但不能说这是否始终是第三个选项

HTML:

<mat-option _ngcontent-vor-c141="" role="option" class="mat-option mat-focus-indicator mat-option-multiple ng-tns-c92-121 ng-star-inserted mat-selected mat-active" id="mat-option-370" tabindex="0" aria-selected="true" aria-disabled="false" style="">
    <mat-pseudo-checkbox class="mat-pseudo-checkbox mat-option-pseudo-checkbox ng-star-inserted mat-pseudo-checkbox-checked"></mat-pseudo-checkbox>
    <!---->
    <span class="mat-option-text">2022-Apr</span>
    <!---->
    <div mat-ripple="" class="mat-ripple mat-option-ripple"></div>
</mat-option>

Dropdown List HTML:

<div class="mat-select-arrow-wrapper ng-tns-c92-121">

<div class="mat-select-arrow ng-tns-c92-121"></div></div>

April 2022取消选中复选框后的HTML:

<mat-option _ngcontent-vor-c141="" role="option" class="mat-option mat-focus-indicator mat-option-multiple ng-tns-c92-121 ng-star-inserted mat-active" id="mat-option-370" tabindex="0" aria-selected="false" aria-disabled="false" style="">
    <mat-pseudo-checkbox class="mat-pseudo-checkbox mat-option-pseudo-checkbox ng-star-inserted"></mat-pseudo-checkbox>
    <!---->
    <span class="mat-option-text">2022-Apr</span>
    <!---->
    <div mat-ripple="" class="mat-ripple mat-option-ripple"></div>
</mat-option>

推荐答案

To uncheck the desired you can click() on the element with text as 2022-Apr using the following locator strategy:

new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//mat-option//span[@class='mat-option-text' and text()='2022-Apr']//preceding-sibling::mat-pseudo-checkbox[1]"))).click();

作为替代方案,您可以使用removeAttribute方法删除classname 101,如下所示:

WebElement element = driver.findElement(By.xpath("//mat-option//span[@class='mat-option-text' and text()='2022-Apr']//preceding-sibling::mat-pseudo-checkbox[1]"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('class')", element);
WebElement newElement = driver.findElement(By.xpath("//mat-option//span[@class='mat-option-text' and text()='2022-Apr']//preceding-sibling::mat-pseudo-checkbox[1]"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('class','mat-pseudo-checkbox mat-option-pseudo-checkbox ng-star-inserted')", newElement);

Java相关问答推荐

如何让TaskView总是添加特定的列来进行排序?

更新我们的一个文物后出现了严重的符号引用错误

试着做一个2x2的魔方求解算法,我如何找到解路径(DFS)?

如何使用值中包含与号的查询参数创建一个java.net.URI

如何使用SpringBoot中的可分页对整数作为字符串存储在数据库中时进行排序

无法使用Java&;TestContainers获取AWS SQS队列的属性

将响应转换为带值的键

Java ArrayList的整数和数组的泛型

有效的公式或值列表必须少于或等于255个字符

Java泛型类方法的静态返回类型是否被类型擦除?

是否有一个Java Future实现可以在池繁忙时在调用者线程中执行?

项目react 堆中doOnComplete()和Subscribe()的第三个参数之间的差异

如果执行@BeForeEach#repository.save(),则测试中的UnitTest最终UUID会发生更改

本机方法(JNI)总是编译的吗?

如何使用Java对随机生成的字母数字优惠券代码进行过期设置

H2数据库仅支持%1个结果集?

我们可以在方法中声明接口吗?

如何在Spring Boot Auth服务器上正确配置CORS?

spring 更新多项管理关系

双对象供应商