I'm trying to fetch the href
attribute from an anchor, and I know the value is a nested URL. For example on https://web.archive.org/web/20230307082148/https://dilbert.com/strip/2023-03-05 the previous button links to https://web.archive.org/web/20230307082148/https://dilbert.com/strip/2023-03-04
.
Selenium only gives me the last part of that, so https://dilbert.com/strip/2023-03-04
.
I tried the suggestion to wait properly, but that doesn't help.
Example code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ExpectedCond
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://web.archive.org/web/20230307082148/https://dilbert.com/strip/2023-03-05")
previous_page = driver.find_element(By.XPATH, "//a[@class='js-load-comic-older']")
print(f"Previous page is {previous_page.get_attribute('href')}")
#From https\://www.delftstack.com/howto/python/python-selenium-webdriver-wait/
previous_page2 = WebDriverWait(driver, 10).until(ExpectedCond.element_to_be_clickable((By.XPATH, "//a[@class='js-load-comic-older']")))
print(f"Previous page that we waited for is {previous_page2.get_attribute('href')}")
gives:
(venv) user@mac dilbert$ python tmp.py
Previous page is https://dilbert.com/strip/2023-03-04
Previous page that we waited for is https://dilbert.com/strip/2023-03-04
Any idea how to get the entire href
...?