Search code examples
python-2.7xpathselenium-webdriverweb-scrapingsendkeys

sendkeys of selenium in python dose not work


I have this code:

from selenium import webdriver
#open Firefox
driver=webdriver.Firefox()
#open arbitrary ur
url="https://www.scopus.com/search/form.uri?display=basic"
driver.get(url)
#click on input  element for writing special word
search=driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")
search.click()
driver.implicitly_wait(5)
#write your special word
search.send_keys("internet of things")
driver.implicitly_wait(5)
search.submit()

Error stack trace :

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <label class="inputTextLabel activeInputLabel"> is not reachable by keyboard

The url is opened and x-path is identified, but send_keys doesn't work. What should I do?


Solution

  • label node is just a "name" of the input field, you cannot send keys to this element. You need to handle text input node instead.

    Assuming HTML looks like

    <div id='txtBoxSearch'>
        <label>Search</label>
        <input type='text'>
    </div>
    

    You can try

    search = driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/input[@type="text"]""")