我有困难找到一个搜索栏上的网页,我试图自动化。我尝试过几种方法,但由于对selenium比较陌生,我不确定还有什么更高级的定位选项。在
故障: 下面是突出显示搜索栏元素(对应于输入)的代码部分
The xpath to the following highlighted section is below:
//*[@id='core-content-container']/div/div[2]/div/div[1]/nav/div/div[2]/form/ul/li[1]/input
但是,当我试图通过xpath查找这个元素时,我得到了一个NoSuchElementException
(我尝试过更短的xpath,但是那些路径提供了相同的错误)
下面是我用来查找此元素的相关代码位:
^{pr2}$因为我要看的正是这条线:
<input type="text" class="form-control ng-pristine ng-untouched ng-valid" ng-model="query" placeholder="Full domain name">
然后我想也许我可以用
driver.find_element_by_css_selector('input.form-control.ng-pristine.ng-untouched.ng-valid')
由于这与第4.7节中有关seleniums python教程的示例相似,我认为这可以完成任务,但也不起作用(我得到另一个NoSuchElementException
)。在
如果您将
NoSuchElementException
作为您提供的异常,可能有以下原因:可能是当您要查找元素时,
DOM
上不存在该元素,因此您应该使用WebDriverWait
实现{a1},直到元素出现,如下所示:可能是这个元素在任何}:
frame
或iframe
内。如果是,则需要在找到如下元素之前切换frame
或{相关问题 更多 >
编程相关推荐