i Need To Print the text which is moving for every 5 seconds,the html code is attacched below:
HTML :
<span class="cd-words-wrapper" style="width: 1170px;">
<b class="is-hidden">Test</b>
<b class="is-hidden">Test</b>
<b class="is-visible">Test</b>
<b class="is-hidden">Test</b>
</span>
My Python code:
Text = driver.find_elements_by_xpath(self.header)
time.sleep(5)
print(Text.text)
The Above is the Wrong way of Getting the Text. Please help me to sort out this.
If you want to print text once it appear in new b
node, try below code:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
while True:
text_node = WebDriverWait(driver, 10).until(visibility_of_element_located((By.CSS_SELECTOR, '.cd-words-wrapper > .is-visible')))
print(text_node.text)
WebDriverWait(driver, 10).until(lambda driver: text_node.get_attribute('class') == "is-hidden")
If you want just to print all text nodes:
for text_node in driver.find_elements_by_css_selector('.cd-words-wrapper > b'):
print(text_node.get_attribute('textContent'))
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.