本文介紹了如何在 Selenium 中獲得“nth-of-type"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 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
這篇關于如何在 Selenium 中獲得“nth-of-type"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!