selenium.common.exceptions.InvalidSelectorException

页面元素如下

<input type="text" maxlength="20" class="form-control search-input">
在selenium中使用如下方式取元素会报错

WebElement searchInput = driver.findElement(By.className("form-control search-input"));
selenium.common.exceptions.InvalidSelectorException
原因:class 属性值中间的空格表示的是后代选择器 , 如上表示的是“form-control”内的“search-input”,改为如下方式即可

WebElement searchInput = driver.findElement(By.className("search-input"));

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章