Files
wevads-platform/scripts/debug_links.py

68 lines
2.6 KiB
Python

import time,os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
SDIR="/opt/wevads/logs/selenium/screenshots"
opts=Options()
for a in ["--headless=new","--no-sandbox","--disable-dev-shm-usage","--window-size=1920,1080",
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"]:
opts.add_argument(a)
d=webdriver.Chrome(options=opts)
d.implicitly_wait(5)
d.get("https://login.microsoftonline.com"); time.sleep(4)
WebDriverWait(d,15).until(EC.element_to_be_clickable((By.NAME,"loginfmt"))).send_keys("OlivierHEUTTE@associationveloreunion.onmicrosoft.com")
time.sleep(1); d.find_element(By.ID,"idSIButton9").click(); time.sleep(4)
WebDriverWait(d,10).until(EC.element_to_be_clickable((By.NAME,"passwd"))).send_keys("Sma21KA@SgHCa")
time.sleep(1); d.find_element(By.ID,"idSIButton9").click(); time.sleep(6)
print("Login OK",flush=True)
# Click Next on Action Required
d.execute_script("var e=document.getElementById('idSubmit_ProofUp_Redirect');if(e)e.click()")
# LONG WAIT - MS SPA needs time
time.sleep(12)
d.save_screenshot(f"{SDIR}/debug_01_{int(time.time())}.png")
# Dump ALL clickable elements
info=d.execute_script("""
var result=[];
var all=document.querySelectorAll('a,button,input[type=submit],span[role=button],div[role=button]');
for(var i=0;i<all.length;i++){
var el=all[i];
result.push({
tag: el.tagName,
text: el.textContent.trim().substring(0,80),
id: el.id || '',
cls: (el.className||'').substring(0,40),
ariaLabel: el.getAttribute('aria-label') || '',
dataTestid: el.getAttribute('data-testid') || '',
visible: el.offsetParent!==null,
w: el.getBoundingClientRect().width
});
}
return result;
""")
for l in info:
if l['visible'] and l['w']>0:
print(f" {l['tag']} text='{l['text'][:50]}' id={l['id']} aria={l['ariaLabel'][:30]} data-testid={l['dataTestid']}",flush=True)
# Search for "different" anywhere in visible text
print("\n=== DIFFERENT ===",flush=True)
diff=d.execute_script("""
var body=document.body.innerText;
var idx=body.toLowerCase().indexOf('different');
if(idx>=0) return body.substring(Math.max(0,idx-20),idx+60);
return 'NOT FOUND';
""")
print(f"Context: {diff}",flush=True)
# Full visible text
print("\n=== VISIBLE TEXT ===",flush=True)
print(d.find_element(By.TAG_NAME,"body").text[:500],flush=True)
d.quit()