【发布时间】:2021-02-23 20:21:11
【问题描述】:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get("https://hapondo.qa/rent/doha/apartments/studio")
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "/html/head/title"))
)
print(element.text)
在无头选项下无法获取页面标题?试图等待,甚至尝试driver.title
【问题讨论】:
-
您遇到的错误是什么?您使用了不正确的定位器 - css_selector 或 xpath ?
-
@Sureshmani 抱歉,现在刚刚更正。但仍未解决问题。
-
您的 WebDriverWait 行在哪里?因为如果我在 print(driver.title) 之前拥有它,它对我来说没问题
-
@MatthewKing 我尝试了多次,但打印出空白。 repl.it/@AmericanY/issue#main.py
标签: python selenium selenium-webdriver webdriverwait page-title