2

SOLVED

Solution: I just used firefox instead of chrome, and the problem magically disappeared!

I have a selenium bot that adds products on a website with given information. This use to work but it doesn't now. I want to paste the description in the textarea but it goes and pastes the description inside the field SEO Title. And chrome browser freezes for some seconds when it comes to pasting the description, this also is new.

It also leaves a little bit of text when clearing, or pasting text in the upper area, I have no idea why.

Code is here.

textarea = driver.find_element_by_css_selector("textarea#content")
textarea.clear()
textarea.click()
textarea.send_keys(str(desc))

This clears the wanted textarea, but sends the keys to the wrong place, need help.

This is the place where it should paste the description

This is the place where it should paste the description

This is the place called SEO Title, and it pastes the description here instead of the textarea

This is the place called SEO Title, and it pastes the description here instead of the textarea

Example image showing the error, text should be in the upper text area

Example of error

untouched image of the two areas mentioned

Image of the area involved in this question

Alper
  • 33
  • 4

1 Answers1

0

To send a character sequence with in the <textarea> you can use either of the following Locator Strategies:

  • Using css_selector:

    textarea = driver.find_element_by_css_selector("textarea.wp-editor-area#content[name='content']")
    textarea.click()
    textarea.clear()
    textarea.send_keys(str(desc))
    
  • Using xpath:

    textarea = driver.find_element_by_xpath("//textarea[@class='wp-editor-area' and @id='content'][@name='content']")
    textarea.click()
    textarea.clear()
    textarea.send_keys(str(desc))
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    textarea = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.wp-editor-area#content[name='content']")))
    textarea.click()
    textarea.clear()
    textarea.send_keys(str(desc))
    
  • Using XPATH:

    textarea = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@class='wp-editor-area' and @id='content'][@name='content']")))
    textarea.click()
    textarea.clear()
    textarea.send_keys(str(desc))
    
  • 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
  • Thanks for your answer, but this also didn't change anything except that it didn't paste a little bit of text on the wanted textarea. – Alper Dec 24 '20 at 16:37