java - 如何在selenium java中识别 'mat-calendar-body-cell'?

标签 java angularjs selenium selenium-webdriver ui-automation

基本上,UI 代码是用 Angular 编写的,我使用 selenium java 进行自动化。我在识别日历的元素时遇到困难。下面是示例代码。请让我知道如何访问日期。

enter image description here

最佳答案

尝试使用以下 CSS 定位器来使用 aria-label 属性识别特定日期:

By.cssSelector("td[aria-label='Jan 1, 2018']") // (or any date that you want to identify)

如果您想要特定日期的 div 元素:

By.cssSelector("td[aria-label='Jan 1, 2018']>div") // (or any date that you want to identify)

您可以参数化日期值以使其更加通用:

public void selectDate(String date)
    By.cssSelector("td[aria-label='" + date + "']") // using string concatenation. you can do Stirng.format method for better readability.

关于java - 如何在selenium java中识别 'mat-calendar-body-cell'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48392531/

相关文章:

java - 使用 Spring 和 Angular 的 Html5 路由

python - Selenium 加载,但不打印所有 HTML

java - 如何使用 selenium webdriver 处理 Safari 中的地理位置弹出窗口?

java - 什么是数据字段?

java - Hibernate 不会在@onetomany 双向关系中使用的连接表中插入行。

java - 替换大字符串中的大量子字符串

java - 在 HMVC 中如何将模型更改事件发送到多个 View ?

angularjs - 谁能解释一下 angularjs 中 $q 服务的使用?

python-3.x - 用 Selenium 刮活聊天直到流结束

javascript - ng grid shift select bug 选择额外的行