2
votes

I want to select the second element of "TIPOPARTICIPANTE" dropdown list in the following website with Chrome webdriver:

https://www.rad.cvm.gov.br/ENET/frmConsultaExternaCVM.aspx

I can select the dropdown list, by the following:

from selenium import webdriver
driver = webdriver.Chrome('D:\\chromeDriver\\chromedriver.exe') # caminho onde o chromedriver.exe está
driver.get('https://www.rad.cvm.gov.br/ENET/frmConsultaExternaCVM.aspx')

dropdown_list = driver.find_element_by_css_selector('#s2id_cboTipoParticipante')
dropdown_list.click()

option = driver.find_element_by_css_selector('li:nth-child(2)') 
option.click() # este comando gerou um erro 'ElementClickInterceptException'

However, in the last line of this script, I got the following error:

Traceback (most recent call last): File "", line 5, in option2.click() File "C:\Users\Raphael\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\Raphael\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\Users\Raphael\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Raphael\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) ElementClickInterceptedException: element click intercepted: Element li class="select2-search-field".../li is not clickable at point (819, 118). Other element would receive the click: div id="select2-drop-mask" class="select2-drop-mask" style=""/div (Session info: chrome=90.0.4430.93)

Can someone, please, help me select the second element ("Companhias Abertas") of this drop-down list?

2
Was the issue resolved? - vitaliis

2 Answers

1
votes

1 Use explicit waits in your code: For this import:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

2 Wait until loader disappears. For this use: invisibility_of_element_located method.

3 Locator for the second option is #select2-drop li:nth-child(3) div, not li:nth-child(2). There are six elements with locator you specified.

Description of locator:

#select2-drop - parent class with id select2-drop

li:nth-child(3) div Third child because first is nth-child(3). div - you need a child of li.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
driver.get('https://www.rad.cvm.gov.br/ENET/frmConsultaExternaCVM.aspx')
wait = WebDriverWait(driver, 15)
wait.until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "div[id=divSplash]")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#s2id_cboTipoParticipante"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#select2-drop li:nth-child(3) div"))).click()

Result: dropdown selected enter image description here

0
votes

Try defining option like this:

option = driver.find_elements_by_css_selector('span.select2-match')[2]