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> running</p>
I want to get the "running" from the element.
How can I do that?
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
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> running</p>
I want to get the "running" from the element.
How can I do that?
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