skip to Main Content

I’m using selenium to change the Yoast SEO meta description of a post in WordPress. However I cannot get this to work.

This is the code of the text box without any text in it:

        <div class="DraftEditor-editorContainer">
            <div aria-autocomplete="list" aria-describedby="placeholder-3oen9" aria-expanded="false" aria-labelledby="3" class="notranslate public-DraftEditor-content" contenteditable="true" role="combobox" spellcheck="false" id="snippet-editor-field-description" style="outline: none; user-select: text; white-space: pre-wrap; overflow-wrap: break-word;">
                <div data-contents="true">
                    <div class="" data-block="true" data-editor="3oen9" data-offset-key="9otfs-0-0">
                        <div data-offset-key="9otfs-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
                          <span data-offset-key="9otfs-0-0">
                            <br data-text="true">
                          </span>
                      </div>
                    </div>
                </div>
            </div>
        </div>

The code of the text box changes if there is text in the box.
This is the box with text in it:

<div class="DraftEditor-editorContainer">
    <div aria-autocomplete="list" aria-describedby="placeholder-3oen9" aria-expanded="false" aria-labelledby="3" class="notranslate public-DraftEditor-content" contenteditable="true" role="combobox" spellcheck="false" id="snippet-editor-field-description" style="outline: none; user-select: text; white-space: pre-wrap; overflow-wrap: break-word;">
        <div data-contents="true">
            <div class="" data-block="true" data-editor="3oen9" data-offset-key="9otfs-0-0">
                <div data-offset-key="9otfs-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">
                  <span data-offset-key="9otfs-0-0">
                    <span data-text="true">EXAMPLE TEXT</span>
                  </span>
                </div>
            </div>
        </div>
    </div>
</div>

As you can see <br data-text="true"> gets changed to <span data-text="true">EXAMPLE TEXT</span>
How would I be able to insert text with this using selenium

2

Answers


  1. Try below:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='notranslate public-DraftEditor-content' and @role='combobox']"))).send_keys("Text Test")
    

    Note : please add below imports to your solution

    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    
    Login or Signup to reply.
  2. Try the following code:

    driver.find_element_by_css_selector('#snippet-editor-field-description').send_keys('test123')
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search