0
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='notranslate public-DraftEditor-content' and @role='textbox']"))).send_keys("This is auto message example.")

Hello, I would like to ask if this can be converted into javascript because I have the whole bot already typed in javascript and only this needs to be converted from selenium python to javascript. Is it possible or do I have to write the whole javascript into selenium?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
wsupreme
  • 1
  • 2

1 Answers1

0

To convert the line of code from to notation, you can use the setAttribute() method and you can use either of the following solutions:

  • Using setAttribute() and innerHTML:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='notranslate public-DraftEditor-content' and @role='textbox']")))
    driver.execute_script("arguments[0].setAttribute('innerHTML','This is auto message example.')", element)
    
  • Using setAttribute() and textContext:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='notranslate public-DraftEditor-content' and @role='textbox']")))
    driver.execute_script("arguments[0].setAttribute('textContext','This is auto message example.')", element)
    

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352