Selenium WebDriver 无法存在元素

问题描述 投票:0回答:1

我正在尝试找到一个要单击的元素。我可以使用 DevTools 从浏览器中找到该元素,但使用 Selenium 时会遇到错误,找不到元素。

我的代码:

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()
driver.implicitly_wait(2)
driver.get("https://www.fsmone.com.my/funds/tools/factsheet/aham-bond-fund?fund=MYAFCAPF")
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH,"//div\[@id='content'\]")))

element=driver.find_element(By.XPATH, "//span\[text()='Latest NAV Price '\]")
element.click()

它返回以下错误

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='Latest NAV Price ']"}
selenium-webdriver web-scraping
1个回答
0
投票

如果没有源代码,你正在使用它很难说,但从这里看来,你只是试图单击文本,而不是按钮。

以点赞为例,

此代码应该适用于按下upvote xpath。

driver.find_element(By.XPATH, '//*[@id="question"]/div[2]/div[1]/div/button[1]').click()
© www.soinside.com 2019 - 2024. All rights reserved.