selenium – 如何在属性中按文本单击日历日期

我遇到的问题是我不想在单击17或18时指定绝对xpath – 而是希望能够通过指定文本来单击。 但链接文本在html中查找href属性,并且我有

属性,我需要帮助如何通过某种方式指定文本来点击它。

以下是驻留在表中的示例html代码:

 17 18 

这是我的selenium代码:

  //click the calendar button driver.findElement(By.xpath("//*[@id='btnTradeDate']")).click(); //go through the calendar table to navigate through each cell WebElement dateWidget = driver.findElement(By.id("transactionGridControls")); List rows=dateWidget.findElements(By.tagName("tr")); List columns=dateWidget.findElements(By.tagName("td")); for (WebElement cell: rows){ //Select 17th Date if (cell.getText().equals("17")){ cell.findElement(By.linkText("17")).click(); //need help on this break;