刚开始学习Selenium。所以网站的检查要素如下:
<select ng-model="selectedFacility" ng-options="facility as facility.name for facility in facilities" ng-change="afterSelectingFacility()" class="ng-pristine ng-valid ng-touched"> <option> </option> </select>
我使用以下代码访问元素:
Select facility = new Select(driver.findElement(By.cssSelector("input[class=('ng - pristine ng - valid ng-touched']")));
但是我收到以下错误:
org.openqa.selenium.InvalidSelectorException: The given selector input[class=('ng - pristine ng - valid ng-touched'] is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: An invalid or illegal selector was specified
我已经浏览了stackoverflow中的一些帖子,但他们没有帮助我。
答案 0 :(得分:0)
使用Css按类选择时,为什么不使用正确的语法?
By.cssSelector("select.ng-pristine.ng-valid.ng-touched")
您也可以使用xpath:
By.xpath("//select[@ng-model='selectedFacility' and @class='ng-pristine ng-valid ng-touched']");
答案 1 :(得分:-1)
你的选择器应该是
By.cssSelector("select[class='ng - pristine ng - valid ng-touched']")
Select facility =new Select(driver.findElement(By.cssSelector("select[class='ng - pristine ng - valid ng-touched']")));
EDIT-I
试试这个
By.cssSelector("select[ng-model='selectedFacility']")