如何通过xpath选择标记

时间:2016-12-19 07:13:09

标签: selenium xpath

我有这个HTML代码

<td ng-repeat="month in fourMonth track by month.month" ng-class="month.class" ng-bind="month.label" ng-click="yearView.setMonth(month)" class="ng-binding ng-scope">Feb</td>

我试图通过使用xpath代码

在selenium中选择
String monthReq = "Feb";
WebElement ele = driver.findElement(By.xpath("//td[ng-bind='month.label' and contains(text(),'"+monthReq+"')]"));

但它没有给出这样的元素异常

Exception in thread "main" org.openqa.selenium.NoSuchElementException:Unable to locate element: //td[ng-bind='month.label' and contains(text(),'Feb')]

1 个答案:

答案 0 :(得分:0)

我认为您的XPath中存在错误。 试试这个 -

//td[@ng-bind='month.label' and contains(text(),'"+monthReq+"')]

//td[contains[text(),'"+monthReq+"']]