Python 无法获取div的文本

Python 无法获取div的文本,python,selenium,dom,xpath,Python,Selenium,Dom,Xpath,元素值为空 注意:上面的HTML代码不是网页上可见的内容任何元素的定位方式都是在DOM上 确保元素位于DOM上的方法与预期的_条件一起使用: old_config_xpath = "//div[contains(text(),'hac-action')]" element_value = wae_base_params[self.driver_key].find_element_by_xpath(old_config_xpath).text 我没有看到该网站的页面源代码,但

元素值为空


注意:上面的HTML代码不是网页上可见的内容

任何元素的定位方式都是在DOM上

确保元素位于DOM上的方法与预期的_条件一起使用:

old_config_xpath = "//div[contains(text(),'hac-action')]"
element_value = wae_base_params[self.driver_key].find_element_by_xpath(old_config_xpath).text

我没有看到该网站的页面源代码,但请测试以下代码,并让我知道结果。在过去,我使用get_属性('innerHTML')而不是'text',它工作正常。如果你能告诉我结果,我会很高兴的

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


wait = WebDriverWait(browser, 10)

element_value = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(text(),'hac-action')]]"))).text

您能发送完整的代码吗?在某些情况下,这可能有效。您可以阅读更多内容,正如OP在问题中指出的,元素不在页面上:因此我的答案。。。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


wait = WebDriverWait(browser, 10)

element_value = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(text(),'hac-action')]]"))).text
old_config_xpath = "//div[contains(text(),'hac-action')]"
element_value = wae_base_params[self.driver_key].find_element_by_xpath(old_config_xpath).get_attribute('innerHTML')