Mam problem z selenem:

Nie mogę kliknąć przycisku, który jest zawarty w wyskakującym wyskakującym przycisku, który klikam.

    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

    # Webdriver
    browser = webdriver.Chrome('C:\\Users\\zlell\\PycharmProjects\\PyroLello\\Userbot\\chromedriver.exe')
    browser.get("https://www.eventbrite.com/e/120621788015")

    # This button originates a pop-up
    python_button = browser.find_element_by_xpath('//*[@id="eventbrite-widget-modal-trigger-120621788015"]')

    # Click
    python_button.click()

    # The pop-up with the new button appears

    # Try to find the button included in the pop-up - Doesn't work
    python_button_2 = browser.find_element_by_css_selector("button.eds-btn.eds-btn--button.eds-btn--fill")

    # Click - Doesn't Work
    python_button_2.click()

Błąd:

// TRACEBACK:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"button.eds-btn.eds-btn--butt
on.eds-btn--fill"}
 (Session info: chrome=86.0.4240.111)
Traceback (most recent call last):
 File "C:\Users\zlell\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-pack
ages\Python38\site-packages\pyrogram\dispatcher.py", line 208, in handler_worker
   await handler.callback(self.client, *args)
 File "C:\users\zlell\PycharmProjects\PyroLello\Userbot\pyro.py", line 318, in test
   python_button_2 = browser.find_element_by_css_selector("button.eds-btn.eds-btn--button.eds-btn--fill")
 File "C:\Users\zlell\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-pack
ages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 598, in find_element_by_css_selector
   return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
 File "C:\Users\zlell\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-pack
ages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
   return self.execute(Command.FIND_ELEMENT, {
 File "C:\Users\zlell\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-pack
ages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
   self.error_handler.check_response(response)
 File "C:\Users\zlell\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-pack
ages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
   raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css
selector","selector":"button.eds-btn.eds-btn--button.eds-btn--fill"}
 (Session info: chrome=86.0.4240.111)

Drugi przycisk - zawarte w pop-up:

Second Button - Included in the pop-up

0
Lello 22 październik 2020, 11:50

1 odpowiedź

Najlepsza odpowiedź

Dodaj czek po obciążeniu strony. Chwyć iframe i przełącz na to.

iframe = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.TAG_NAME, "iframe")))
browser.switch_to.frame(iframe)
python_button_2 =WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "button.eds-btn.eds-btn--button.eds-btn--fill")))

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
0
Arundeep Chohan 22 październik 2020, 10:19