How To Automate Typing Inwards 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 exam illustration that needs to automate writing of html code inwards tinymce. I've tried several approach that failed - I'll non utter most them but focus on the ii others that worked:

1.) Using firefox driver
FirefoxProfile firefoxProfile = novel FirefoxProfile(); firefoxProfile.setEnableNativeEvents(true); firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); driver = novel 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 1 plant best
System.setProperty("webdriver.chrome.driver", "C:\\java\\jar\\chromedriver.exe"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized")); driver = novel 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 merely because it tin lav display html code. Firefox driver exactly displays the html every bit patently text.
For your reference, hither 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> 
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.