【发布时间】:2019-04-27 02:04:35
【问题描述】:
所以我有这个link,我正试图从这个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)
还有:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
我也用过这种等待方式:
self.driver.implicitly_wait(10)
此时我如何获取文本:
self.driver.find_element_by_xpath(xpath).text
我在这里遇到的问题是文本在某些情况下拒绝出现,而在其他情况下却出现,即使找到了实际的 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
【问题讨论】:
标签: python html selenium selenium-webdriver xpath