pythonseleniumselenium-webdriverwebdriverwaitpage-title

Python selenium get page title


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)

Unable to get page title under headless option? Tried to wait and even tried driver.title


Solution

  • You need to take care of a couple of things as follows:


    Solution

    To extract the Page Title you need to induce WebDriverWait for the title_contains() and you can use either of the following Locator Strategy:


    References

    You can find a couple of relevant detailed discussions in: