0

I wrote a few lines of code to automate the filling of the fields in the form. For this purpose I used selectors, I also used .xpath e.g.

Driver.findElement(By.cssSelector("#login")).click();
Driver.findElement(By.cssSelector("#login")).sendKeys

I have come to the point where I want to add text in the field (inside frame?) for adding text, or preferably paste the text. However, for the sake of rehearsals. I want to click inside the box and fill it with the word TEST.

The frame with the text editor inside looks like this

I have already tried to click on it through the selector, through .xpath (full .xpath also) but still nothing happens.

This is what this iframe code looks like

<iframe src="" frameborder="0" class="cke_wysiwyg_frame cke_reset" style="width: 578px; height: 100%;" title="Rich Text Editor, content" aria-describedby="cke_25" tabindex="0" allowtransparency="true"></iframe>

Snapshot of the frame:

Larger iframe fragment (highlighted where text padding appears: <p> <br> </p>)

I found advice on iframe without id on the forum (here), but trying to implement them also does not bring the effect of clicking inside this frame and supplementing it with even simple text.

Interestingly, and maybe helpful with the help of the Selenium IDE plugin for Google Chrome, I recorded and recreated the fragment of what I want to do, i.e. clicking on the frame and entering the text. The recording and replay of these movements works fine, but it has led me to no clue as to how I can solve my problem.

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

1 Answers1

0

To send a character sequence within the <p> <br> </p> as the the desired element is within an iframe you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.

  • Induce WebDriverWait for the desired elementToBeClickable().

  • You can use either of the following locator strategies:

  • Using cssSelector:

    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[class*='cke_reset'][title^='Rich Text Editor'][aria-describedby^='cke'][src]")));
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("body.cke_editable.cke_editable_themed.cke_contents_ltr[contenteditable='true']"))).sendKeys("Martin");
    
  • Using xpath:

    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@class, 'cke_reset') and starts-with(@title, 'Rich Text Editor')][starts-with(@aria-describedby, 'cke') and @src]")));
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//body[@class='cke_editable cke_editable_themed cke_contents_ltr' and @contenteditable='true']"))).sendKeys("Martin");
    

Reference

You can find a couple of relevant discussions in:

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