如何定位Yahoo.finance中的时间选择按钮?
How to locate the time choosing button in Yahoo.finance?
我想在 Yahoo Stock History 页面中找到时间选择按钮:
元素快照:
![在此处输入图片描述][2]
但是我用xpath写的python代码无法使it.The代码如下:
WebDriverWait(browser, 180).until(EC.presence_of_element_located((By.XPATH, '//svg[@class="Va(m)! Mstart(8px) Stk($linkColor) Fill($linkColor) dateRangeBtn:h_Fill($linkActiveColor)
button1 = browser.find_element(By.XPATH,'//svg[@class="Va(m)! Mstart(8px) Stk($linkColor) Fill($linkColor) dateRangeBtn:h_Fill($linkActiveColor) dateRangeBtn:h_Stk($linkActiveColor) W(8px) H(8px) Cur(p)"]')
但是会报错如下:
enter image description here
要么
enter image description here
请给我一些帮助,否则 suggestions.I 不知道为什么找不到它。
该元素是一个动态元素。所以点击你需要诱导的元素:WebDriverWait for the element_to_be_clickable()
and you can use either of the following :
使用CSS_SELECTOR
:
driver.get("https://finance.yahoo.com/quote/AAPL/history?p=AAPL")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "section[data-test=qsp-historical] div[data-test=dropdown] > div > span"))).click()
使用XPATH
:
driver.get("https://finance.yahoo.com/quote/AAPL/history?p=AAPL")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//section[@data-test='qsp-historical']//div[@data-test='dropdown']/div/span"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
我想在 Yahoo Stock History 页面中找到时间选择按钮:
元素快照: ![在此处输入图片描述][2]
但是我用xpath写的python代码无法使it.The代码如下:
WebDriverWait(browser, 180).until(EC.presence_of_element_located((By.XPATH, '//svg[@class="Va(m)! Mstart(8px) Stk($linkColor) Fill($linkColor) dateRangeBtn:h_Fill($linkActiveColor)
button1 = browser.find_element(By.XPATH,'//svg[@class="Va(m)! Mstart(8px) Stk($linkColor) Fill($linkColor) dateRangeBtn:h_Fill($linkActiveColor) dateRangeBtn:h_Stk($linkActiveColor) W(8px) H(8px) Cur(p)"]')
但是会报错如下: enter image description here 要么 enter image description here 请给我一些帮助,否则 suggestions.I 不知道为什么找不到它。
该元素是一个动态元素。所以点击你需要诱导的元素:WebDriverWait for the element_to_be_clickable()
and you can use either of the following
使用
CSS_SELECTOR
:driver.get("https://finance.yahoo.com/quote/AAPL/history?p=AAPL") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "section[data-test=qsp-historical] div[data-test=dropdown] > div > span"))).click()
使用
XPATH
:driver.get("https://finance.yahoo.com/quote/AAPL/history?p=AAPL") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//section[@data-test='qsp-historical']//div[@data-test='dropdown']/div/span"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC