[英]Python selenium select text element by style
On this page ' https://www.nj.gov/health/cd/topics/covid2019_dashboard.shtml ', I try to get the number of New Jersey Positives (upper right of the dashboard).在此页面“ 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)
it always show 0.它总是显示0。
What did I do wrong?我做错了什么? Thanks.
谢谢。
Please find solution请找到解决方案
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.