from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
# ---------------------------------------------------
# KONFIGURATION
# ---------------------------------------------------
USERNAME = "Username"
PASSWORD = "Passwort"
DOWNLOAD_DIR = r"C:\Users\ch-ha\Documents\Belegtransfer\364307-56696\Rechnungseingang"
LOGIN_URL = "
https://sso.geschaeftskunden.dhl.de/aut ... ethod=S256"
RECHNUNGEN_URL = "
https://geschaeftskunden.dhl.de/billing ... e/overview"
# ---------------------------------------------------
# SELENIUM EINRICHTEN
# ---------------------------------------------------
chrome_options = Options()
chrome_options.add_experimental_option("prefs", {
"download.default_directory": DOWNLOAD_DIR,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome(options=chrome_options)
# ---------------------------------------------------
# LOGIN
# ---------------------------------------------------
driver.get(LOGIN_URL)
time.sleep(3)
driver.find_element(By.ID, "username").send_keys(USERNAME)
driver.find_element(By.ID, "password").send_keys(PASSWORD)
driver.find_element(By.ID, "kc-login").click()
time.sleep(5)
# ---------------------------------------------------
# ZU DEN RECHNUNGEN NAVIGIEREN
# ---------------------------------------------------
driver.get(RECHNUNGEN_URL)
time.sleep(5)
# ---------------------------------------------------
# FALLS DIE RECHNUNGEN IN EINEM IFRAME SIND → WECHSELN
# ---------------------------------------------------
iframes = driver.find_elements(By.TAG_NAME, "iframe")
if len(iframes) > 0:
driver.switch_to.frame(iframes[0])
time.sleep(2)
# ---------------------------------------------------
# ALLE BUTTONS "Rechnung herunterladen" FINDEN
# ---------------------------------------------------
download_buttons = driver.find_elements(By.XPATH,
"//*[contains(text(), 'Rechnung herunterladen')]"
)
print(f"Gefundene Rechnungen: {len(download_buttons)}")
# ---------------------------------------------------
# ALLE BUTTONS ANKLICKEN
# ---------------------------------------------------
for btn in download_buttons:
try:
btn.click()
print("Download gestartet...")
time.sleep(2)
except Exception as e:
print("Fehler beim Download:", e)
print("Alle sichtbaren Rechnungen wurden heruntergeladen.")
driver.quit()