Lucian Blaga
Lucian Blaga

Reputation: 147

selenium: is not reachable by keyboard

I try to publish gist on gist.github.com using python/selenium, This is my current code:

driver.find_element(By.NAME, "gist[contents][][name]").send_keys("file.md")

#import pdb; pdb.set_trace()

tmp = driver.find_element(By.NAME, "gist[contents][][value]").send_keys("Description file")
#keyboard.write("Description file")


driver.find_element(By.XPATH, "//button[@name=\'gist[public]\']").click()

time.sleep(30)

The code is paritial working, i have big problem on gist[contents][][name] input, app kill and return me this error: is not reachable by keyboard... i don't have ideea how i can fix this error, does anyone know how i can solve this problem?

full error:

admin$ python github_login.py 
Traceback (most recent call last):
  File "github_login.py", line 31, in <module>
    tmp = driver.find_element(By.NAME, "gist[contents][][value]").send_keys(".")
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <textarea class="form-control file-editor-textarea js-blob-contents js-code-textarea " name="gist[contents][][value]"> is not reachable by keyboard

Upvotes: 2

Views: 5368

Answers (2)

amin jahani
amin jahani

Reputation: 92

I had the same issue with my code. I could not set the entry for input send_keys(). as I understand this happens because that element is kinda hidden and must be clicked on first.

Element is not reachable by keyboard in plain words means that the element can’t be reached using the keyboard, which means you won't physically interact with it even.

So all you need to do is to change the element to clickable and then use send_keys() or whatever function you desire to use.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(By.NAME, "xxx")
)
element.send_keys("yyy")

note: this link has some useful examples and documentations about element_to_be_clickable

Upvotes: 0

frianH
frianH

Reputation: 7563

You can use this locator:

.find_element(By.CLASS_NAME, "CodeMirror-lines")

And also use ActionChains.

First you need following import:

from selenium.webdriver import ActionChains

Try the bellow code:

driver.get("https://gist.github.com/")
driver.find_element(By.NAME, "gist[description]").click()
driver.find_element(By.NAME, "gist[description]").send_keys("GIST DESCRIPTION")
driver.find_element(By.NAME, "gist[contents][][name]").send_keys("file.md")

#HERE
el = driver.find_element(By.CLASS_NAME, "CodeMirror-lines")
ActionChains(driver).move_to_element(el).click(el).send_keys('Description file').perform()

Upvotes: 4

Related Questions