[英]Print the Moving text Every 5 Seconds in selenium python
我需要打印每5秒鍾移動一次的文本,以下是html代碼:
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>
我的Python代碼:
Text = driver.find_elements_by_xpath(self.header)
time.sleep(5)
print(Text.text)
以上是獲取文本的錯誤方法。 請幫我解決這個問題。
如果要在文本出現在新的b
節點中后對其進行打印,請嘗試以下代碼:
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")
如果只想打印所有文本節點:
for text_node in driver.find_elements_by_css_selector('.cd-words-wrapper > b'):
print(text_node.get_attribute('textContent'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.