基本上,UI代码是用Angular编写的,我正在使用Selenium Java实现自动化。我在确定日历元素方面面临困难。下面是示例代码。请让我知道如何访问日期。
最佳答案
尝试使用以下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.