How to get the content of CKeditor using WebDriver - selenium

I'd like to be able to test the content in CKeditor using webdriver.
However there are some hurdles; firstly CKeditor uses Iframes, and there are several Iframes on the page, so not sure how to switch reliably to it using WebDriver as they don't have specific names.
In addition, the content inside the editor is within a <body></body> tag inside the iframe. I'm not sure how to get WebDriver to return the content reliably.
Has anyone actually tried to do this in their tests? If so, how did you achieve it?
Thanks.

You can use the CKEditor api and execute javascript. Not sure which selenium driver you are using but here is the java script you can use to get the HTML for:
"return CKEDITOR.instances['youreditoridhere'].getData();"

u may refer this
http://bharath-marrivada.blogspot.com/2012/03/fckeditor-switch-activeelement.html
hopes this help ;D

Related

How to write and execute xpath in IE browser

My application works in Internet Explorer and I want to write xpath to create selenium test suite.Please suggest how to write and execute xpath in IE browser.
You can install Firebug which is an Add-on for Firefox. Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
You can also generate Xpath and use it in your code.
It is unclear what you want to achieve. XPath over downloaded HTML text, XPath over generated DOM in browser page, XPath over some XML taken either from XML island in browser page or from external source...
If you need to evaluate XPath on existing page this page should be treated as XHTML or XML document by IE. I.e. not any page has native support for XPath.
If the page is not xmlDocument you could read page dom and create clone XML.
Once you have XML then simplest is to use libs like xml4jquery or AmdHarness-amd-xml and evaluate XPath in JavaScript.
If you need to run XPath on someone else's page the easiest way is to run JS by bookmarklet. Something like http://xmlaspect.org/XmlView . The bookmarklet gives the JS string as a function body to be run by Selenuim code.
LMN if the bookmarklet is the solution you are looking for, I will create one for XPath.
The selenium web driver allows to run script as well:
String title = (String)jse.executeScript(
"return document.evaluate(xPath, node, null, 9, null).singleNodeValue");
But you still need the XML source and code for extracting the XPath results as string, array, NodeList where JS libraries at your service.

Identifying ExtJS elements with selenium webdriver

I am having handling a drop down button in EXTJS application which i am trying to automation with selenium web driver.
clicking on the image i will get a list of elements in the form of 's
to click select from
Please help me how i can device a xpath to click this image, which i should not use "id" (as its extjs it might vary every now and then).
if there are any selector i can use for extjs please suggest. Thanks for your help.
<DIV id=ext-gen2337 class=x-form-field-wrap style="WIDTH: 0px"><INPUT id=ext-gen2023 class=" x-form-text x-form-field" style="WIDTH: 297px" readOnly size=24 value="Clients with pending exceptions" name=ext-gen2023 autocomplete="off"><IMG id=ext-gen2338 class="x-form-trigger x-form-arrow-trigger" src="https:REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif">
Try below XPath to match required img element:
//input[#value="Clients with pending exceptions"]/following-sibling::img
So if you want to start testing ExtJS app and you don't want to use the best solution for this such as Sencha Test or Bryntum Siesta.
The best way to approach this is to write you own layer between the ExtJS components and the html dom of the site.
You can see more info in my answer here https://stackoverflow.com/a/41718879/1768843
But what you need to do is to use the Ext.Component.Query, with Selenium you can execute the javascript code on the site. So you execute the ext query and you pass there the Ext selector - for example button[text=something] or panel[name=mainPanel] simply any ExtJS component selector. This will return you the ExtJS object and with it you can simply call .getDom() or .getId() which will return you the actual dom or id used in the HTML. Next you can simply use the webdriver functions for clicking (or something) on the HTML elements in the site.
^^ You need to do this because the ExtJS framework can generate the HTML every-time little bit differently. For example you add new container or you upgrade your ExtJS version and the HTML is changed and your test can stop working. But if you call the Ext components as log as the Ext source code is still the same your tests will be always working.
But doing this is quite a hassle and lot of work. It's much better to use prepared solutions such as Sencha Test where everything is already prepare for testing ExtJS apps.
I would do something like this:
driver.findElement(By.xpath("//div[contains(#class, 'x-form-field-wrap')]//img"));
or
driver.findElement(By.xpath("//img[contains(#src, 'https://REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif')]"));

Is it possible to inject html into my selenium tests?

So lets say we have WebElement foo. foo has a crazy looking, consistently changing xpath. Hardcoding foo gets really annoying when you have to constantly do so.
I just discovered the html edit on Firebug and it made me wonder, is there anyway I could just write in id values for use in my Selenium tests? The distinct lack of no id values in any of the WebElements under test is getting real old.
Thanks in advance.
Editing the HTML in Firebug or Chrome devtools is just transient. As soon as you close the browser, your changes go away. There is no real solution to what you are asking other than to request that your devs add IDs to the desired elements. I'm assuming you don't own the site or that's not possible or you would have mentioned it. Welcome to test automation where the site creators don't take test automation into account when creating a site... :)
For the question, Is it possible to inject html into my selenium tests, the answer is yes. You can use JavaScriptExecutor to inject html into your WebPage.
((JavascriptExecutor) driver).executeScript("arguments[0].id = 'abc';", element);
Just as JeffC mentioned, for injecting the id or any HTML, you would have to identify the required element first. Also, the changes will be lost after you refresh the page.

How to work with iframe which is part of a webpage but not getting identified through webdriver?

I am trying to automate a webpage using webdriver,here i am struck with a iframe,which i dont know how to handle.
While i choose css for the iframe by selecting with ,it gives me #xEditingArea
again if I search the same iframe using the css or id,it is not identifying anything.
I tried everything
I want to write some message with the message body which is iframe.
Can anyone guide me how to handle this?
Thanks in advance.
If it is only one iFrame on your website you could try to access it with XPath and the tagname.
Directly accessing iframes is not possible, it has its own DOM elements and we have to switch to that particular frame and then perform the actions you want.
To select the iframe you want to work with, do:
driver.switchTo().frame("frame1");
Now, your driver set to work with the DOM the iframe one.
It's important to remember that maybe switching "back" will be needed. It's done like this:
driver.switchTo().defaultContent();
Using Python Selenium WebDriver, you can access a frame using:
from selenium import webdriver
browser = webdriver.Firefox()
browser.switch_to_frame("fame_name_or_id")
If you want to confirm that the frame was access correctly, just print out the page contents using:
print browser.page_source

How can I write Selenium test case for a specific GWT Widget?

I'm very new to Selenium. I want to write Selenium test cases for GWT widget. I can wirte test case for HTML elements since they have id, but i'm not able to do the same in GWT. I want to test widgets such as textboxes, images, listbox etc.
Can anyone help me?
Thanks in advance,
Gnik
Now I set debugId for the GWT widgets. Using that Id I can access the elements and test.
For eg. In UiBinder set id as <g:TextBox ui:field="textBox" debugId="userBox"
In the java code, textBox.ensureDebugId("userBox");
I can access these widgets in Selenium as follows,
selenium.type("gwt-debug-userBox", "testing");
I don't know if selenium is the right tool to test GWT Widgets, I think there are special tools for that.
With Selenium you can automate the browser. If GWT doesn't provide ids for its html elements there are various other ways to locate your elements. For example you can use xpath or css selectors. Just check the Selenium documentation.
But again, be careful about what you want to test. You don't want to test that GWT Widgets create a proper Web application, that is done already. You probably want to use a special GWT test tool where you test the java side of your widget.