Luís Eduardo
Luís Eduardo

Reputation: 52

Selenium unable to locate element - Frame

I'm trying to create a python script using selenium to fill the searching box on the site: http://acervo.bndigital.bn.br/sophia/index.html. My code:

chromedriver = "./chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get('http://acervo.bndigital.bn.br/sophia/index.html')
time.sleep(2)
driver.find_element_by_css_selector('#div_rap > table > tbody > tr > td > form > input.input_busca').send_keys('test')

I've already tried to use find_element_by_css_selector and find_element_by_xpath but it didn't work. I got the error message:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#div_rap > table > tbody > tr > td > form > input.input_busca"}

I don't know why this is happening.

Upvotes: 0

Views: 221

Answers (2)

SeleniumUser
SeleniumUser

Reputation: 4177

You are facing issue due to iframe. you need to switch to iframe before you start entering your text to inputbox.

Please refer below solution :

driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("http://acervo.bndigital.bn.br/sophia/index.html")
driver.find_element_by_tag_name('frame').send_keys("Keys.ESCAPE")
driver.switch_to.frame("mainFrame")
inputBox = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@name='rapida_campo']")))
inputBox.send_keys("your test")

Output:

enter image description here

Upvotes: 1

dinolin
dinolin

Reputation: 78

Try this one..

input_element = driver.find_element_by_xpath("/html/body/div[1]/div[1]/table/tbody/tr/td/form/input[1]")
input_element.send_keys("Enter your value")
input_element.submit()

Upvotes: 0

Related Questions