Python selenium xpath获取文本为空

Val*_*ali 1 html python selenium xpath selenium-webdriver

所以我有这个链接,我试图从这个 XPath 获取文本//div[@class='titlu'],但由于某种原因,有时我得到的文本应该是这样的,有时我收到一个空字符串,即使该网站包含该文本。

我尝试过什么:

wait = WebDriverWait(self.driver, 10)   
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Ap. de lux 3 ")))
e = self.driver.find_element_by_xpath(html_data.xpath)
Run Code Online (Sandbox Code Playgroud)

还:

wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
Run Code Online (Sandbox Code Playgroud)

我也使用过这种类型的等待:

self.driver.implicitly_wait(10)
Run Code Online (Sandbox Code Playgroud)

我此时如何获取文本:

self.driver.find_element_by_xpath(xpath).text
Run Code Online (Sandbox Code Playgroud)

我在这里遇到的问题是,文本在某些情况下拒绝出现,而在其他情况下却出现,即使实际的 XPath 已找到并且它已经存在。也许没有完全加载,你们能给我一些关于如何解决这个问题的建议吗?

更新:

另外,我试图使用 selenium 获取它的位置和大小,但它们都将为 0。知道如何解决这个问题吗?

with, height = self.driver.find_element_by_xpath(html_data.xpath).size x, y = self.driver.find_element_by_xpath(html_data.xpath).location

eww*_*ink 5

的第一个元素//div[@class='titlu']是隐藏的,如果使用您将不会获得值,.text因为它只会提取可见文本,使用.get_attribute('textContent')或选择第二个元素。