In the website, I want to scrape there are different dropdown lists. I want to open before copying data.
I have structured the flow like this:
buttons = driver.find_elements(By.CSS_SELECTOR, 'svg[class = "undefined event__expander event__expander--close"]')
for button in buttons:
button.click()
But if I run it, I can open only the first list and the others are still closed. Any tips?
CodePudding user response:
driver.maximize_window()
wait=WebDriverWait(driver,20)
driver.get('https://www.diretta.it/')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button#onetrust-accept-btn-handler"))).click()
buttons = driver.find_elements(By.CSS_SELECTOR, 'svg[class = "undefined event__expander event__expander--close"]')
for button in buttons:
button.click()
It might have been due to the accept cookies but your code works after you click it.
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC