0

I want to select an option of an form using a Selenium to automate an task of download. Here're the steps of what i need to do:

1st. - Click into a bar of the "Formulário" enter image description here

2st. - Select the option "Relatório de Emissão Tokio ID1000013" enter image description here

I'm using the follow code to make theses steps, but in the end (in this part describe above) the code doesn't run.

from selenium import webdriver
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select

servico = Service(ChromeDriverManager().install())

navegador = webdriver.Chrome(service=servico)
navegador.implicitly_wait(10)
navegador.get('http://site.com.br')
navegador.implicitly_wait(10)
navegador.find_element('xpath', "//a[@id='linkMenu_1500']").click()
navegador.implicitly_wait(10)
navegador.find_element('xpath', "//a[@id='menu_1501']").click()
navegador.implicitly_wait(10)
navegador.find_element('xpath', "//a[@id='subMenu1000006']").click()
navegador.implicitly_wait(10)
element = navegador.find_element_by_xpath("//input[@id='id_formulario']")

But the code above returns this:

AttributeError                            Traceback (most recent call last)
Cell In[20], line 14
     10 navegador.implicitly_wait(10)
     11 # Selecione a opção "Relatório de Emissão Tokio" no formulário
     12 #lect = Select(navegador.find_element_by_id("id_formulario"))
     13 #elect.select_by_value("1000013")
---> 14 element = navegador.find_element_by_xpath("//input[@id='id_formulario']")

AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'

Please, how can I do this tasks using Selenium?

Obs.: The page source code of this bar is:

<select class="form-control fichaCampo campoform" id="id_formulario" name="id_formulario" eng_idcoluna="1000835" title="Formulário" eng-possui-condicao="True" eng-executa-condicao-invisivel="False" eng-preenche-campos="dv_periodo,cd_tp_apolice,cd_status,nm_descricao" eng-index-linha="0" eng-sql-datatype="int" data-toggle="popover">
<option>
</option>
    <option value="1000010">Acumulo&nbsp;por&nbsp;tomadores&nbsp;com&nbsp;Grupo&nbsp;Econômico&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID1000010
</option>
    <option value="592">Followup&nbsp;de&nbsp;Tomadores&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000592
</option>
    <option value="1000009">Gerencial&nbsp;-&nbsp;Cotação/Propostas/Estudos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID1000009
</option>
    <option value="322">Gerencial&nbsp;-&nbsp;Produção&nbsp;por&nbsp;Periodo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000322
</option>
    <option value="475">Relatório&nbsp;de&nbsp;Acúmulo&nbsp;Geral&nbsp;da&nbsp;Exposição&nbsp;do&nbsp;Tomador&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000475
</option>
    <option value="492">Relatório&nbsp;de&nbsp;Acúmulo&nbsp;Geral&nbsp;da&nbsp;Exposição&nbsp;do&nbsp;Tomador&nbsp;-&nbsp;CCG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000492
</option>
    <option value="1000013">Relatório&nbsp;de&nbsp;Emissão&nbsp;Tokio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID1000013
</option>
    <option value="366">Relatório&nbsp;de&nbsp;Emissões&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000366
</option>
    <option value="562">Relatório&nbsp;Geral&nbsp;de&nbsp;Tomadores&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID0000562
</option>
    <option value="1000007">Relatório&nbsp;Gerencie&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID1000007
</option></select>

1 Answers1

0

The method you're using no longer works You should use this

from selenium.webdriver.common.by import By

navegador.find_element(By.XPATH, value="YOUR XPATH HERE")
Mohamed Darwesh
  • 659
  • 4
  • 17
  • This method didn't work. The code returns "NoSuchElementException" in navegador.find_element(By.XPATH, value="//input[@id='id_formulario']") line – Victor Soares Apr 19 '23 at 14:32
  • @VictorSoares Make sure you're entering the correct XPATH, alternatively you could try Adding a WebDriverWait to ensure that the element is present on the page before clicking on it – Mohamed Darwesh Apr 19 '23 at 14:42
  • XFranko, still doesn't work. I put the correct XPATH in the code: navegador.find_element(By.XPATH, value="//select[@id='id_formulario']") and I also put an WebDriverWait like !navegador.implicitly_wait(10)" before execute the method find by XPATH. --------------------------------------------------------------------------- NoSuchElementException Traceback (most recent call last) – Victor Soares Apr 19 '23 at 14:54