'Python - Webscraping - Select item in Dropdown

***> I'm trying to select an item in the dropdown and I'm not getting the > dropdown, it stops at the part and doesn't select the item I want - > Decarbonization Credit or "CBIO - Decarbonization Credit" from the > first dropdown. Can you help me?? Thank you very much

##my python code##

import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from pandas import ExcelWriter
import time
from selenium.webdriver.support.select import Select
import select
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup



driver = webdriver.Chrome(ChromeDriverManager().install())

driver = webdriver.Chrome()

driver.get('http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v05_series_introducao.asp?str_Modulo=Ativo&int_Idioma=1&int_Titulo=6&int_NivelBD=2/')
driver.find_element_by_xpath('//*[@id="divContainerIframeBmf"]/div/dl/dd[2]/a').click()
find_dp1 = \
driver.find_element(By.NAME,"ativo")
select_find_dp1 = Select(find_dp1)
select_find_dp1.select_by_visible_text("CBIO - Crédito de descarbonização")

time.sleep(3)


Solution 1:[1]

The target page is a bit more complex: first you need to switch to iframe and next to frame:

driver.get('http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v05_series_introducao.asp?str_Modulo=Ativo&int_Idioma=1&int_Titulo=6&int_NivelBD=2/')
driver.find_element_by_xpath('//*[@id="divContainerIframeBmf"]/div/dl/dd[2]/a').click()
driver.switch_to.frame(driver.find_element(By.XPATH, '//iframe[@name="dados_corpo"]'))
driver.switch_to.frame(driver.find_element(By.XPATH, '//frame[@name="ativo"]'))
find_dp1 = driver.find_element(By.XPATH, '//select[@name="ativo"]')
select_find_dp1 = Select(find_dp1)
select_find_dp1.select_by_visible_text("CBIO - Crédito de descarbonização")

time.sleep(3)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gangabass