0

What I am trying to do is, to take the content from a currently opened web browser text field, edit it and paste back. I can get the text like this:

def getText():
    text = chrome.find_elements_by_id("HTMLEditor")[0].get_attribute("value")
    return text

and it works fine. But after changing the text, I do this:

def paste(text):
    chrome.find_elements_by_id("HTMLEditor")[0].send_keys(text)

in the function "paste", I get "element not interactable". I know the area chrome.find_elements_by_id("HTMLEditor")[0] is valid since I can get the text from there.

So what am I doing wrong? Thanks.

Berdan Akyürek
  • 212
  • 1
  • 14

2 Answers2

0

Sometimes, clicking the element before sending keys helps. Perhaps try something like:

def paste(text):
    WebDriverWait(chrome,10).until(EC.element_to_be_clickable((By.ID, "HTMLEditor"))).click()
    chrome.find_elements_by_id("HTMLEditor")[0].send_keys(text)

WebdriverWait needs these imports:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
0buz
  • 3,443
  • 2
  • 8
  • 29
0

To copy the content from the web browser text field the desired element needs to be visible, which satisfies in your case. Ideally, to copy the content you should induce WebDriverWait for the visibility_of_all_elements_located() and you can use the following Locator Strategy:

def getText():
    text = WebDriverWait(chrome, 10).until(EC.visibility_of_all_elements_located((By.ID, "HTMLEditor")))[0].get_attribute("value")
    return text

Similarly, to paste the content, the desired element needs to be interactable. So, to copy the content you need to you need to induce WebDriverWait for the visibility_of_all_elements_located() and you can use the following solution:

def paste(text):
    WebDriverWait(chrome, 10).until(EC.visibility_of_all_elements_located((By.ID, "HTMLEditor")))[0].send_keys(text)
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352