css - (NodeJS) Selenium Webdriver findElement.By.css() 页面有多个时只返回一个值
问题描述
这是有问题的代码块:
var webdriver = require('selenium-webdriver')
var chrome = require('chromedriver')
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build()
driver.get("http://thewebsite.com").then(x => {
driver.findElement(webdriver.By.css("[title^='ANI:']")).then(selObject => {
console.log(selObject)
selObject.getAttribute("title").then(x => console.log(x))
})
})
这是我要提取的页面源:
<tbody id="CONFGROUP_0">
<!-- dynamic content here -->
<tr id="35534" style="background-color: rgb(228, 225, 229);">
<td nowrap="" valign="middle" height="30" width="210" title="ANI: 7076 DNIS: 7791" style="font-size: 0.8em;"><div style="overflow: hidden; display: inline; float: left; padding-top: 3px; width: 210px;"><div style="display: inline; padding-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%;">SOC OPS ALERT</div><input type="text" maxlength="50" style="display: none;"></div><div style="display: none; float: right; padding-right: 10px; height: 30px;"><img src="images/talkshow/03_buttonlower_on.gif" style="margin-top: 6px;"></div></td>
</tr>
<tr id="35533" style="background-color: rgb(255, 255, 255);">
<td nowrap="" valign="middle" height="30" width="210" title="ANI: 8017057799 DNIS: 7076" style="font-size: 0.8em;"><div style="overflow: hidden; display: inline; float: left; padding-top: 3px; width: 210px;"><div style="display: inline; padding-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%;">8017057799</div><input type="text" maxlength="50" style="display: none;"></div><div style="display: none; float: right; padding-right: 10px; height: 30px;"><img src="images/talkshow/03_buttonlower_on.gif" style="margin-top: 6px;"></div></td>
</tr>
</tbody>
当我document.querySelectorAll("[title^='ANI:")
在 Chrome 控制台中运行时,它会返回我需要的两个元素。但是,当我findElement
在上面的代码块中运行 find 时,它只返回一个对象。如果我运行driver.executeScript("document.querySelectorAll(\"[title^='ANI:\")")
,它将返回null
。
我希望findElement
它会返回它找到的所有东西,并且从我环顾四周来看,它看起来应该这样做。我什至添加了一个超时,以确保在进行搜索之前页面已完全加载,但仍然没有。
任何帮助将非常感激。
解决方案
原来findElements
存在,我是个白痴。谢谢你们
elements = driver.findElements(webdriver.By.css("[title^='ANI:']"))
推荐阅读
- ios - Swift:估计的高度不适用于 UICollectionView
- html - 为什么我需要将“[0]”添加到我的数据以使其呈现,如果我不这样做,则会出现错误?
- html - chrome mobile上发生触摸时如何禁用蓝色边界框?
- mysql - 查看每个模型的每日活跃用户
- python - 解析日志行并将唯一 IP 保存为 JSON blob
- r - 为分类变量创建交互式可选图
- javascript - 有没有更好的方法来处理快递中的错误?
- python - pyinstaller制作成EXE后工作代码崩溃
- jquery - 在 select2 jQuery 中加载预定义的选项
- python - Wx 小部件不可点击