Reputation: 3306
I'm trying to retrieve text from a text box of containers/cards from this google forms. Basically I want to retrieve the questions and the related answers.
Question Test boxes inside a container have more or less the following html code:
<textarea
class="appsMaterialWizTextinputTextareaInput exportTextarea"
jsname="YPqjbf"
data-rows="0"
tabindex="0"
aria-label="Intitulé de la question"
jscontroller="RKFxf"
jsaction="input:Lg5SV;ti6hGc:XMgOHc;rcuQ6b:WYd;"
data-disable-newlines="true"
dir="auto"
data-initial-dir="auto"
data-initial-value="How do you feel about your next vacation after COVID-19?"
style="height: 24px;">
How do you feel about your next vacation after COVID-19?
</textarea>
I thought my code could do it, but the result is blank:
# I get all the card with questions and answers inside
containers = driver.find_elements_by_class_name(
"freebirdFormeditorViewItemcardRoot.item-dlg-affectsIndex.item-dlg-dragTarget"
)
print("containers: ", containers)
# for each card
for container in containers:
try:
# Get the question
question = container.find_element_by_class_name(
"appsMaterialWizTextinputTextareaInput.exportTextarea"
)
except NoSuchElementException:
print("NoSuchElementException: ")
continue
print("question: ", question.text)
The result
question:
Nothing ... It seems that question gets all the textarea and not the one specific to the card/container.
Upvotes: 2
Views: 163
Reputation: 1747
Try to get it by the aria-label attribute using CSS selector like following :
question = container.find_element_by_css_selector(".exportTextarea[aria-label='Intitulé de la question']")
Selenium can't get an element that has multiple classes with find_element_by_class_name
the only way to achieve that is using CSS selector like this :
find_element_by_css_selector("classOne classTwo")
Upvotes: 4