Где я сейчас:
Я могу найти баннер с cookie_banner в своем коде:
Код: Выделить всё
cookie_banner = page.locator('//cmm-cookie-banner').Код: Выделить всё
accept_button = cookie_banner.locator('//button[text()="Alle akzeptieren"]')Код: Выделить всё
if cookie_banner:Однако для обоих isVisible() имеет значение false/ заканчивается по тайм-ауту.
Также я попробовал разные вещи, предложенные вторым пилотом. (
Код: Выделить всё
wait_for_timeout(5000)Во всплывающем браузере я вижу диалоговое окно и могу щелкнуть кнопка, значит она там!
Вот полный код:
Код: Выделить всё
try:
cookie_banner = page.locator('//cmm-cookie-banner')
if cookie_banner:
print('Banner ist da')
accept_button = cookie_banner.locator('//button[text()="Alle akzeptieren"]') # Beispiel für den Button
if accept_button:
if cookie_banner.is_visible():
print('Das Element ist sichtbar.')
else: print('Das Element ist nicht sichtbar.')
if cookie_banner.is_hidden():
print('Das Element ist verborgen.')
else: print('Das Element ist nicht verborgen.')
if cookie_banner.is_enabled():
print('Das Element ist aktiviert.')
else:
print('Das Element ist deaktiviert.')
computed_styles = cookie_banner.evaluate('element => window.getComputedStyle(element).visibility')
display_styles = cookie_banner.evaluate('element => window.getComputedStyle(element).display')
print(f'Visibility: {computed_styles}')
print(f'Display: {display_styles}')
print('button auch')
#accept_button.scroll_into_view_if_needed()
time.sleep(1)
accept_button.click(force=True)
print('Cookie-Banner akzeptiert.')
else:
print('Akzeptieren-Button nicht gefunden.')
else:
print('Cookie-Banner nicht sichtbar.')
except Exception as e:
print(f'Fehler: {e}')
Код: Выделить всё
Timeout zu ende
eval zu ende
Banner ist da
Das Element ist nicht sichtbar.
Das Element ist verborgen.
Das Element ist aktiviert.
Visibility: visible
Display: inline
button auch
Подробнее здесь: https://stackoverflow.com/questions/793 ... playwright
Мобильная версия