[英]Python selenium select text element by style
在此頁面“ https://www.nj.gov/health/cd/topics/covid2019_dashboard.shtml ”上,我嘗試獲取新澤西陽性的數量(儀表板的右上角)。
positiveCount = driver.find_elements_by_xpath("//text[@style='stroke-width: 2; font-size: 160px; line-height: normal;']")
print len(positiveCount)
它總是顯示0。
我做錯了什么? 謝謝。
請找到解決方案
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
url = 'https://www.nj.gov/health/cd/topics/covid2019_dashboard.shtml'
driver.get(url)
driver.maximize_window()
iframe = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.TAG_NAME, 'iframe')))
driver.switch_to.frame(iframe)
svg = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, 'text')))
print svg.text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.