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 automate typing in tinymce using selenium java How to automate typing in tinymce using selenium java Reviewed by Edward Legaspi on Sunday, March 10, 2013 Rating: 5

No comments:

Powered by Blogger.