Error: selenium web driver java cannot locate tinyMCE

driver.switchTo().frame("tinymce_iframe");    
String script="var editor=tinyMCE.get('tinymce_textarea');";    
JavascriptExecutor js=(JavascriptExecutor) driver;    
js.executeScript(script);    

I'm encountering a WebDriverException while trying to run this javascript code, as it returns an error stating that tinyMCE is not defined.

<html>  
<script type="text/javascript" src="tinymce3.5.1/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

      <script type="text/javascript">
       tinyMCE.init({
        theme : "advanced",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        mode : "exact",
        elements : "tinymce_textarea"
      });
     </script>  
      <body>

     <textarea cols="80" rows="10" id="tinymce_textarea" name="tinymce_textarea"> 

         &lt;h1&gt;<span id="1">Article</span> <span id="2">Title</span>&lt;/h1&gt;
         <p><span id="3">Here's</span> <span id="4">some</span> <span id="5">sample</span> <span id="6">text</span> <span id="7">Hello</span> <span id="8" >World.</span> </p>
           </textarea>
</body>
</html>

Answer №1

Not sure if you have found a solution to your issue yet. Here are some suggestions to troubleshoot the problem without using tinyMCE or Selenium.

It appears to be a timing issue related to the iframe loading. Instead of using a timer, consider implementing an event listener. Wrapping the init function seemed to work for me. I came across a helpful tip in this forum post:

tinyMCE.execCommand('mceRemoveEditor', false, 'editorId');
setTimeout(function() {
    tinyMCE.init(myconfig);
}, 3000);

Alternatively, if you can identify the proper editor element, try using setInterval():

var IntID = setInterval(function () { // Repeated check for Editor
    if (($('.tinymce_textarea').length) > 0) { // Editor element length
        tinyMCE.init({
            theme : "advanced",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            mode : "exact",
            elements : "tinymce_textarea"
        });
        clearInterval(IntID); // This will clear timer for editor check
    }
}, 10);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for managing multiple selection list boxes with Selenium

Can anyone assist me with Selenium commands or code to retrieve data from a list? We are only allowed to select the data from the list and text entry (such as auto-search) is not permitted. I tried using the code below, but was unable to resolve the issue ...

Preserve present condition following a jQuery click event

I'm facing a challenge where I need to hide a button upon clicking another button, but the problem is that when the page refreshes, the hidden button becomes visible again. My objective is to keep it hidden even after refreshing the page and only reve ...

Clicking on Only One Card in Material UI React

I've encountered an issue with my code: const useStyles = makeStyles({ card: { maxWidth: 345, }, media: { height: 140, }, }); export default function AlbumCard(props) { const classes = useStyles(); let ...

Tips on executing a dynamic testng.xml file via the Maven command line with the "mvn test" command

I have developed a custom test runner that generates a dynamic TestNG XML file to execute test suites with parameters. All @Test methods are included in their respective classes, such as LoginTest.class. The test runner works perfectly when executed from t ...

The requested org.openqa.selenium.remote.CapabilityType import could not be resolved

Having trouble with Selenium 3.4.0 and importing specific packages? import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; Check out my Maven dependencies for Selenium: <dependency> <gro ...

JavaScript Ajax request lags significantly in Internet Explorer, while it executes instantly in Firefox

So I have this jQuery .ajax() call set up to retrieve a List<string> of IP addresses from a specific subnet. I'm using a [WebMethod] on an .aspx page to handle the request and ASP.NET's JSON serializer to format the response for my Javascri ...

Steps for raising a unique error in an asynchronous callout

As I work on making async API callouts, there might be a need to throw custom errors based on the outcome. Also, part of this process involves deleting objects from S3. try { await s3.deleteObject(bucketParams); //Since S3 API does not provide ...

Deciphering the GWT compiler's results

Although I'm not a JavaScript developer, I'm currently delving into the process of converting Java code to JS using the GWT compiler in order to identify the root cause of memory growth in our extensive application. Every now and then, I come ac ...

Facing unexpected behavior with rxjs merge in angular5

import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/merge'; this.data = this.itemsCollection.valueChanges() this.foo = this.afs.collection<Item>('products') .doc('G2loKLqNQJUQIsDmzSNahlopOyk ...

Tips for resolving Vue.js static asset URLs in a production environment

I included the line background-image: url(/img/bg.svg); in my CSS file. During development mode, this resolves to src/img/bg.svg since the stylesheet is located at src/css/components/styles.css. However, when I switch to production mode, I encounter a 40 ...

Tips for reorganizing the JSON data created by Artoo.js?

My file aims to scrape data from a single webpage, but I've hit a roadblock. I initially tried using artoo, request, and cheerio based on my research. Here's the code I have so far: request('http://www.ciclopi.eu/frmLeStazioni.aspx?ID=144&a ...

A guide to locating elements based on text without considering capitalization with Selenium and Xpath

I am currently working with Java version "1.8.0_191" and Selenium 3.141.59. My goal is to determine if a page contains the words "error" or "erreur", regardless of case sensitivity. Locating the text is simple: List<WebElement> elementList = drive ...

Trouble with linkage in jQuery for AJAX requests in an external .js document

My asp.net application has a master file that includes the jquery.js file. On another page that uses this master page, I have my own jquery code. I attempted to move this code to an external file and then include it in my .aspx file. While most functions ...

The sorting process fails to make any changes, thus leaving the state unaffected

Is there a way to sort an array of objects in descending order by their id? No errors appear in the console. Even after calling the sort method, the state of allPosts remains unchanged. import { useState } from "react"; import Button f ...

“Unlocking the secret to extracting color from an image in React Native”

While it may sound like a silly question, I am new to the world of React technology. I am looking to extract colors from an image - for example, when a user selects an image to upload, I want to identify all the colors used in that image. If this is possib ...

The @FindBy annotation in Webelement fails to return a valid reference, resulting in a

When I try to invoke the method Spage.editExButton(int ID), I encounter an issue where WebElement first is null and an error occurs. I have already defined it using the @FindBy annotation, so why is it still null? To work around this problem, I have to exp ...

Downloading Laravel Excel Files via an Ajax Call

Is it possible to generate an Excel file using Laravel with PHPSpreadsheet (PHP lib) and then send the XLSX file to the frontend for download? JSX Section axios .get( "/excel/export/dashboardTable", {} ) .then(resp => { //success call ...

update the element that acts as the divider in a web address (Angular)

Is it possible to modify the separator character used when obtaining the URL parameters with route.queryParams.subscribe? Currently, Object.keys(params) separates the parameters using "&" as the separator. Is there a way to change this to use a differe ...

Trigger an alert when a button is clicked and redirect the user to an newly opened tab

I recently created a button with a link that opens in a new tab. I also implemented some JavaScript to display an alert. Everything is working as expected, but after the user clicks "OK" on the alert, they remain on the same page. I would like to automati ...

Error when spaces are present in the formatted JSON result within the link parameter of the 'load' function in JQuery

I am facing an issue with JSON and jQuery. My goal is to send a formatted JSON result within the link using the .load() function. <?php $array = array( "test1" => "Some_text_without_space", "test2" => "Some text with space" ); $json = jso ...