Get Text from an element with Selenium (Python)

Question:

I want to get the text of an element with Selenium.

Element:

<p
    class="sc-168cvuh-1 cNxwvb">

    <svg
        aria-hidden="true"
        focusable="false"
        data-prefix="fas"
        data-icon="circle"
        class="svg-inline--fa fa-circle fa-w-16 fa-fw sc-168cvuh-2 frUsNu"
        role="img"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 512 512"
        _css="[object Object],[object Object]">
        <path
            fill="currentColor"
            d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z">
        </path>
    </svg>&nbsp;running</p>

I want to get the "running" from the element.

How can I do that?

Asked By: ErsterImChat

||

Answers:

This may work:

wait = WebDriverWait(driver, 10)
desired_text = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[contains(@class, 'sc-')]"))).text
print(desired_text)

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Answered By: cruisepandey
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.