我对硒有疑问:我无法单击由我单击的第一个按钮生成的弹出窗口中包含的按钮。 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()
1 回答
慕田峪7331174
TA贡献1828条经验 获得超13个赞
添加页面加载后的等待。抓住 iframe 并切换到它。
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")))
进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
添加回答
举报
0/150
提交
取消