在 Selenium 中使用 .getAttribute 获取文本数据

Getting text data with .getAttribute in Selenium

我正在尝试从 this Google form 上的 container/card 文本框中检索文本。我基本上想检索问题和相关答案。

我可以使用 css 代码检索问题,但我不知道如何获得答案。此类代码中或多或少包含了答案:

<input type="text" class="quantumWizTextinputSimpleinputInput exportInput" jsname="YPqjbf" autocomplete="on" tabindex="0" aria-label="valeur d'une option" value="Doctor's availability in hotel" dir="ltr" data-initial-value="Doctor's availability in hotel">

这里的答案是:

data-initial-value="Doctor's availability in hotel"

这里我们要得到:

data-initial-value="Doctor's availability in hotel"

所以,我用 `.get_attribute' 尝试了下一个:

# I get all the letters with the questions and answers inside
containers = driver.find_elements_by_class_name(
    "freebirdFormeditorViewItemContentWrapper"
)
questionnaire = {}
# for each card
for container in containers:
    try:
        question = container.find_element_by_css_selector(".exportTextarea[aria-label='Intitulé de la question']")
    except NoSuchElementException:
        print("NoSuchElementException in " + container)
        continue
    # Get the answers
    responses = container.find_elements_by_class_name(
        "quantumWizTextinputSimpleinputInput.exportInput"
    )
    print("responses: ", responses)
    extracted_responses = [response.get_attribute("data-initial-value") for response in responses]

    questionnaire[question.text] = extracted_responses 

但我没有得到答案:

responses:  []

尝试:

responses = container.find_element_by_css_selector(
  ".quantumWizTextinputSimpleinputInput.exportInput"
)