In Selenium I want to print out a span element called:
<td class="Fw(b) Fz(s) Ta(end) Pb(20px)" data-reactid="60">
<span data-reactid="61">23,849,000</span>
</td>
I need to print out "23,849,000".
I have tried this, but it doesn't seem to work:
print driver.find_element_by_xpath('''//*[@id="Col1-1-Financials-Proxy"]''').text
If you know a solution that might help, I would really appreciate your help as I don't know the answer.
Required value generated dynamically, so you need to wait until it appeared in DOM:
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
print(wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//span[@data-reactid='61']"))).text)
try with :
driver.find_element_by_xpath('.//div[@class="Fw(b) Fz(s) Ta(end) Pb(20px)"]')
You need to specify the correct path to reach the text inside span
To print the span element as per the given HTML
you can use the following line of code :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# code block
print(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='Col1-1-Financials-Proxy']//td[@class='Fw(b) Fz(s) Ta(end) Pb(20px)']//following::span[1]"))).get_attribute("innerHTML"))
print(driver.page_source)
为我工作
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.