如何在 Selenium 中获得“nth-of-type"
- 作者: 名字十五个字实在太长我怕记不住
- 来源: 51数据库
- 2023-01-30
问题描述
我正在使用 Selenium Webdriver 来检查这个特定段落的文本(此处以蓝色突出显示的那个):
I'm using Selenium Webdriver to check the text of this particular paragraph (the one highlighted in blue here):
但我如何查询"该段落?
But how do I 'query' that paragraph?
这是我正在尝试的(不工作):
This is what I'm trying (not working):
def test_intro_text(self):
"""Test that intro text is expected text"""
container = self.browser.find_element_by_id('visual-17')
hed_dek_wrapper = container.find_element_by_class_name('hed-dek-wrapper')
intro_text = hed_dek_wrapper.findElement('p:nth-of-type(2)')
self.assertIn(
'Over the past 20 years, we have seen an evolution.',
intro_text.text
)
我收到此错误:AttributeError: 'WebElement' object has no attribute 'findElement'
I'm getting this error: AttributeError: 'WebElement' object has no attribute 'findElement'
推荐答案
findElement() 不是 Python.请尝试以下方法:
findElement() is not a Python. Try below instead:
intro_text = hed_dek_wrapper.find_element_by_css_selector('p:nth-of-type(2)')
assert 'Over the past 20 years, we have seen an evolution.' in intro_text.text
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
