How to automate typing in tinymce using selenium java
Tech-Today

How to automate typing in tinymce using selenium java


Prerequisites:
  1.) selenium-java
  2.) selenium-firefox-driver
  3.) selenium-chrome-driver
  4.) chromedriver - http://code.google.com/p/chromedriver/downloads/list


Currently I'm working on a a test case that needs to automate writing of html code in tinymce. I've tried several approach that failed - I'll not talk about them but focus on the 2 others that worked:

1.) Using firefox driver
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setEnableNativeEvents(true);
firefoxProfile.setPreference("extensions.firebug.currentVersion",
"1.8.1");
driver = new FirefoxDriver(firefoxProfile);

driver.switchTo().frame("frameId_ifr");
driver.findElement(By.id("tinymce")).clear();
driver.findElement(By.id("tinymce")).sendKeys("Hello world");

2.) Using chrome driver, this one works best
System.setProperty("webdriver.chrome.driver", "C:\\java\\jar\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
driver = new ChromeDriver();

driver.switchTo().frame("longDescription_ifr");
driver.findElement(By.id("tinymce")).clear();
((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<h1>
Hello czetsuya</h1>
'");

I favored chrome driver simply because it can display html code. Firefox driver just displays the html as plain text.
For your reference, here is my pom.xml:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>




- How To Setup Your Google Code Repository To Be Accessible In Maven
This tutorial will teach us how we can setup a google code project, so we can make the artifact accessible via maven. Requirements: 1.) You should have an account in google code. The trick is just simply forming the correct url to be access by maven....

- How To Use Primefaces With Jboss 7.1.3
This tutorial will teach us how to use primefaces with jboss 7.1.3. Requirements:  1.) primefaces 3.5  2.) jboss 7.1.3  3.) maven javaee6 generated project (ear, war, ejb) Steps: 1.) Add primefaces module in jboss.   a.) In JBOSS_HOME/modules...

- How To Enable Jersey Rest Api In A Maven Web Project
This tutorial assumes that you already know how to create a maven project in eclipse. Steps: 1.) Create a new maven web project. (this assumes that you have maven plugin installed in your eclipse). 2.) In your META-INF/web.xml file make sure that you...

- How To Add Pmd Reporting To Maven
Before proceeding to this exercise, you may want to try my tutorial on how to setup a maven project to eclipse: http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html. Assuming you have follow the tutorial above, you should...

- How To Install Selenium 1.0.10 On Firefox 4.0.1
Unfortunately it seems selenium doesn't support the latest version of firefox yet. To get around this security issue do the following: 1.) In firefox go to about:config. 2.) Click yes in the warning message 3.) The next screen is like a registry window...



Tech-Today








.