Selenium not submiting return button

I’m trying to submit a search in a brazilian stock market webpage.

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Firefox()

browser.get('https://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/empresas-listadas.htm')
time.sleep(10)
searchBar = browser.find_element_by_xpath('//*[@id="keyword"]')
searchBar.send_keys("Petrobras")

searchBar.submit()

But when I run my code I got the following error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id="keyword"]
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:183:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.jsm:395:5
element.find/</<@chrome://remote/content/marionette/element.js:300:16

I insert the geckodriver.exe into my python folder. What is wrong with my code?

NOTE: The search bar used in xpath element is Nome da Empresa or Digite o Nome da Empresa

>Solution :

<iframe id="bvmf_iframe" width="100%" height="2000px" frameborder="0" allowfullscreen="" scrolling="auto" src="https://sistemaswebb3-listados.b3.com.br/listedCompaniesPage/?language=pt-br"></iframe>

Your element is in an iframe. To click on the elements inside you need to switch to it prior.

wait=WebDriverWait(browser,60)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"bvmf_iframe")))

Import:

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

Leave a Reply