Trying to get the number “6” from this html:
JavaScript
x
10
10
1
<div color="pain" class="sc-fAyiZu hNLuuN">
2
<svg width="15" height="12" viewBox="0 0 15 12" fill="#7c82cb" data-testid="increase" color="pain" class="sc-jMZWZw iQTebp">
3
<path d="M9.05 11.95a1 1 0 00.71-.29l4.95-4.95a1 1 0 00.2-.3A1 1 0 0015 6a1 1 0 00-.07-.36 1 1 0 00-.2-.3l-4.97-5a1 1 0 10-1.42 1.42L11.59 5H1a1 1 0 000 2h10.59l-3.25 3.24a1 1 0 00.71 1.71z"></path>
4
</svg>
5
6
6
<div class="sc-bIaGYP cHxEYS">
7
Text 2
8
</div>
9
</div>
10
Using this Selenium code:
JavaScript
1
5
1
element = WebDriverWait(driver, 40).until(
2
EC.element_to_be_clickable((By.XPATH, xpathToElement)))
3
4
element = driver.find_element_by_xpath(xpathPain).text
5
Getting the result from element:
JavaScript
1
3
1
"6
2
Text 2"
3
I.e. both the parent and the child elements text.
Advertisement
Answer
Try this xpath : .//div[@class=’sc-fAyiZu hNLuuN’].getAttribute(“innerText”).split(“”)[0]