0

I tried to use xpath search but it didn't work for me. The idea is that I pass the mouse over "Nota Fiscal" and then go down with the mouse in the drop-down menu and click on "Emissão". The drop-down menu is inside a frame called "pag_principal" and the rest of the code (which is not here) works within that frame, that is, selenium has switched windows and frames correctly... Inspect elements My problem is: selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view.

How can i fix this?

The code I made to try is this:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys

bot.get('https://www.nfs-e.net/fiscalweb.php')
time.sleep(3)

campo_login = bot.find_element_by_xpath("//input[@name='login_temp']") 
campo_login.clear()
campo_login.send_keys(self.usuario)
password = bot.find_element_by_xpath('//*[@id="passw_temp"]')
password.clear()
password.send_keys(self.senha)   
password.send_keys(Keys.RETURN)
time.sleep(6)
# handling to new window
bot.switch_to.window(bot.window_handles[1])
bot.maximize_window()

def envio(self):
   bot = self.bot
   time.sleep(5)
   bot.switch_to.frame("pag_principal")
   time.sleep(2)

# this is the part that I want selenium to select the item "Emissão" in the drop-down menu "Nota Fiscal"

   Nota_fiscal = WebDriverWait(bot, 100000).until(EC.element_to_be_clickable((By.XPATH, "/html/body/table/tbody/tr[1]/td/div/div/ul[1]/li[5]/div/ul/li[1]/a/span"))).click()
   time.sleep(2)
   Emissão = bot.find_element_by_xpath('/html/body/table/tbody/tr[1]/td/div/div/ul[1]/li[5]/div/ul/li[1]/a/span').click()

[Trying by using select]

Menu = bot.find_element_by_class_name("menu") 
mySelectElement = bot.find_element_by_xpath('/html/body/table/tbody/tr[1]/td/div/div/ul[1]/li[5]/a/span') 
dropDownMenu = Select(mySelectElement) 
WebDriverWait(bot, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/table/tbody/tr[1]/td/div/div/ul[1]/li[5]/div/ul/li[1]/a/span")))
dropDownMenu.select_by_visible_text('Emissão') 
time.sleep(2) 
Emissão = bot.find_element_by_xpath('/html/body/table/tbody/tr[1]/td/div/div/ul[1]/li[5]/div/ul/li[1]/a/span').click() 

[I want to click on "Emissão" within the "Nota Fiscal" drop-down menu (I don't know how to edit html)]


    <div class="titulo_sistema">Nota Fiscal Eletrônica</div>  <ul class="menu"><li><a href="javascript:void(0)"><span> Globais </span></a><div><ul><li><a href="javascript:void(0)"><span class="span_sub_menu">Cadastros</span></a><div><ul><li><a href="javascript:void(0)"><span class="span_sub_menu">Diversos</span></a><div><ul><li><a onclick="carrega_rotina_menu(1026,118,event)" href="javascript:void(0)"><span class="span_menu" title="Alterar Senha/E-Mail">Alterar Senha/E-Mail</span></a></li><li><a onclick="carrega_rotina_menu(3565,101,event)" href="javascript:void(0)"><span class="span_menu" title="CPFCNPJ x Email">CPFCNPJ x Email</span></a></li><li><a onclick="carrega_rotina_menu(3561,101,event)" href="javascript:void(0)"><span class="span_menu" title="Procuração Digital">Procuração Digital</span></a></li></ul></div></li><li><a href="javascript:void(0)"><span class="span_sub_menu">Pessoas/Endereços</span></a><div><ul><li><a onclick="carrega_rotina_menu(3503,101,event)" href="javascript:void(0)"><span class="span_menu" title="Bairro">Bairro</span></a></li><li><a onclick="carrega_rotina_menu(3504,101,event)" href="javascript:void(0)"><span class="span_menu" title="Logradouro">Logradouro</span></a></li><li><a onclick="carrega_rotina_menu(1014,101,event)" href="javascript:void(0)"><span class="span_menu" title="Pessoa">Pessoa</span></a></li><li><a onclick="carrega_rotina_menu(3572,101,event)" href="javascript:void(0)"><span class="span_menu" title="Estrangeiros">Estrangeiros</span></a></li></ul></div></li></ul></div></li><li><a href="javascript:void(0)"><span class="span_sub_menu">Consultas</span></a><div><ul><li><a href="javascript:void(0)"><span class="span_sub_menu">Economico</span></a><div><ul><li><a onclick="carrega_rotina_menu(3517,101,event)" href="javascript:void(0)"><span class="span_menu" title="Atividades">Atividades</span></a></li><li><a onclick="carrega_rotina_menu(3526,101,event)" href="javascript:void(0)"><span class="span_menu" title="Cadastro Econômico">Cadastro Econômico</span></a></li></ul></div></li><li><a href="javascript:void(0)"><span class="span_sub_menu">Pessoas/Endereços</span></a><div><ul><li><a onclick="carrega_rotina_menu(3525,101,event)" href="javascript:void(0)"><span class="span_menu" title="Cidade">Cidade</span></a></li><li><a onclick="carrega_rotina_menu(3506,101,event)" href="javascript:void(0)"><span class="span_menu" title="Pessoa">Pessoa</span></a></li><li><a onclick="carrega_rotina_menu(3573,101,event)" href="javascript:void(0)"><span class="span_menu" title="Estrangeiros">Estrangeiros</span></a></li></ul></div></li></ul></div></li></ul></div></li><li><a href="javascript:void(0)"><span>Autorização</span></a><div><ul><li><a onclick="carrega_rotina_menu(9710,101,event)" href="javascript:void(0)"><span class="span_menu" title="Solicitação de Cancelamento de NFSe">Solicitação de Cancelamento de NFSe</span></a></li><li><a onclick="carrega_rotina_menu(4505,101,event)" href="javascript:void(0)"><span class="span_menu" title="Utilização de NFSe">Utilização de NFSe</span></a></li></ul></div></li><li><a href="javascript:void(0)"><span>Configurações</span></a><div><ul><li><a onclick="carrega_rotina_menu(4514,101,event)" href="javascript:void(0)"><span class="span_menu" title="Cabeçalho da NFSe">Cabeçalho da NFSe</span></a></li></ul></div></li><li><a href="javascript:void(0)"><span>Consulta</span></a><div><ul><li><a onclick="carrega_rotina_menu(4524,101,event)" href="javascript:void(0)"><span class="span_menu" title="NFS-e Prestadas">NFS-e Prestadas</span></a></li><li><a onclick="carrega_rotina_menu(4506,101,event)" href="javascript:void(0)"><span class="span_menu" title="NFS-e Tomadas">NFS-e Tomadas</span></a></li></ul></div></li><li><a href="javascript:void(0)"><span>Nota Fiscal</span></a><div><ul><li><a onclick="carrega_rotina_menu(9598,656,event)" href="javascript:void(0)">**<span class="span_menu" title="Emissão">Emissão</span>**</a></li><li><a onclick="carrega_rotina_menu(9597,109,event)" href="javascript:void(0)"><span class="span_menu" title="Cancelamento">Cancelamento</span></a></li><li><a onclick="carrega_rotina_menu(4501,101,event)" href="javascript:void(0)"><span class="span_menu" title="Gerenciamento de Notas">Gerenciamento de Notas</span></a></li><li><a onclick="carrega_rotina_menu(4511,436,event)" href="javascript:void(0)"><span class="span_menu" title="Exportação">Exportação</span></a></li></ul></div></li>     <li>        <a href="javascript:void(0)" onclick="parent.window.close(0,event)"><span> Sair </span></a>     </li>  </ul>  <ul style="float:right;">     <li style="width:25px;max-height:25px;padding:3px;text-align:center;cursor: pointer;color:#104E8B;" title="Início" id="home-button">         <i class="fa fa-home" style="font-size:18px;padding-top:3px;cursor: pointer;" onclick="abre_tela_inicial();"></i>     </li>     <li style="width:25px;max-height:25px;text-align:center;padding:3px;" title="Usuário" id="perfil-usuario">         <i class="fa fa-user" style="font-size:18px;padding-top:3px;cursor: pointer;" onclick="abrePerfilUsuario()"></i>     </li>     <li style="float:right;height:35px;margin-right: 35px; padding-left:5px;background:none;position:block;" id="lipesquisa" name="lipesquisa">         <input type="text" id="container_pesquisa" name="container_pesquisa" class="container_busca campo_externo_suggest" placeholder="Pesquisa" onfocus="focusPesquisa(this, 'in')" onblur="focusPesquisa(this, 'out')" suggest="true" autocomplete="off"><script>  $(document).ready(function(){$("#container_pesquisa").autocompletepesquisa({"aCamposVisualizacao":["frm_tit"],"iRotina":"16","sCampoProcurado":"frm_tit","sCampos":"container_pesquisa:frm_tit","sSessao":"3cbtrg9e3c1eil54cupilua6s1","sUrlAbrir":"","sNome":"form","iRotChamou":"0","iAcaChamou":"20","bAutoComplete":true,"aAjaxCampos":["container_pesquisa"],"bAjaxComplete":true});}); if ($.browser.msie) {      if($.browser.version == 9.0 || $.browser.version == 8.0) {          $('#container_pesquisa').css('padding-top','3px');          $('#container_pesquisa').css('background-position','5px -1px');      }  }</script>     </li>  </ul>

First I need to hover over these elements for the drop-down menu to appear

<span>Nota Fiscal</span>

And the element I want to click on is this

<span class="span_menu" title="Emissão">Emissão</span>
6
  • Does this answer your question? How to select a drop-down menu value with Selenium using Python? Commented Feb 19, 2020 at 4:33
  • Hello, @KentKostelac, I tried to use select like that but I can't use it with span elements Message: Select only works on <select> elements, not on <span> Commented Feb 19, 2020 at 14:17
  • I've edited your question. In the future just edit your question. And then add a comment to bring attention to it. As you can see; Code written in a comment is not readable Commented Feb 19, 2020 at 14:26
  • More importantly. You should try using attributes to find the elements you need to use. Copy pasting the xpath from a browser is not going to work in all cases. Also in your xpath. You are selecting a <span> not a <select> Commented Feb 19, 2020 at 14:27
  • Give us a minimal verifiable sample of the HTML you are trying to select from so we can identify what is wrong with your xpath. Because right now all I can tell you is that your xpath is wrong. And a picture does not count. Commented Feb 19, 2020 at 14:35

1 Answer 1

0

Your xpath is completely wrong. Of course nothing is going to happen when you press a span. Try clicking its parent that is an <a>

And try using proper xpaths and not just something you copy pasted from the browser.

//span[@class='span_menu' and @title='Emissão']::parent/a

I repeat. If you provide a minimal HTML example. It will be much easier to help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.