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.
Related
I am getting Cannot locate an element using By.xpath error in Selenium using Java(IE11). I am working on a web page created using Adobe AEM(CQ5).
I have tried the following possible solutions but neither of it helped.
Tried to add wait.
Switch to active window.
Tried even on Chrome.
Bring focus on element.
Currently using the absolute path (/html/body/div[4]/header[1]/div[1]/div[2]/div[5]/div[1]/nav/ul[1]/li[3]/a) but also used relative path (.//*[#id='cq-gen188']/nav/ul/li[3]/a).
Also searched whether there is any iframe involved. Unfortunately there was none.
To find the xpath, I have used FirePath plugin in Firefox. When i search for the element using the xpath in Firefox, i am successful. But when i execute the code i get the error.
If you are in the correct IFRAME then you can use
driver.findElement(By.id("cq-gen188"));
Remember that ID is always unique and that's a core assumption for all of the libraries in the authoring UI whether it is from core AEM framework or from custom components.
Your problem may be due to incorrect IFRAME as AEM neatly makes the UI look like a seamless window but there are IFRAME in place to facilitate various authoring navigation experiences.
i want to identify the web element for the selenium script using any plug in example in firefox we use a firepath . is plug in for chrome to identify the webelement .i have tried with developers tool but using developers tool not getting clear locator?
In most browsers just right-click on chosen element on webpage and choose 'Inspect'/'Inspect element' etc and the developer tools would open with marked HTML code for that element.
If that html code didn't show you unique ID for that element it means that you need to:
use xpath to find element by unique text inside (dont use xpath is slow)
or css selector to find it by unique attribute of that element
or asks dev team to add proper unique id/attibute to that element, and thats the best option
I'm currently working on a node/express.js app for which I'm writing some e2e tests in nightwatch. Today I hit a roadblock while trying to search for an element using the XPath locator strategy. Basically I can search for elements using any of the following:
//div[#data-pino-name='userIdSection']
//input[#name="password"]
//input[#name="username"]
//button[#data-pino-name="submit"]
//a[#data-pino-name="cancel"]
By the way, all of the selectors above work fine using the chrome tools.
However, using the following:
//pre[#data-pino-name="requiredErrorMessage"]
doesn't work at all. I'm surprised since I expected the <pre> tag to be treated the same as any other html tag. However, the test returns a "element was not found" for all elements with the pre tag.
Anyone guidance would be appreciated.
You can follow this approach in writing XPath based on your scenario
//div[#data-pino-name='userIdSection']/pre
//div[#data-pino-name='userIdSection']/pre[#data-pino-name="requiredErrorMessage"]
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
Can anyone tell me what is the exact flow of taking out xpath in Selenium-IDE.
After trying alot by putting alerts i m not getting how to take out the exact xpath.
Selenium displays the xpath according to xpath:position and some others ways also but i want to add the xpath traversing from html i.e the topmost position.How can i do that???
I've come to prefer CSS selectors over Xpath. The IDE won't create them for you, but with a little practice they're very easy to write. As a bonus, they make your tests much easier to maintain.
For example, let's say you have a button with the text "save". The locator would be:
css=button:contains('save')
Check out http://www.w3.org/TR/css3-selectors/ for more detail.
I use XPather to find out the xpath. Then I use the resulting path in the Selenium IDE to cross verify. You could also use other tools like XPath Checker or Firebug to do the same.
Write 1 line of code in javascript:
LocatorBuilders.order = ['id', 'link', 'name', 'dom:name', 'xpath:link', 'xpath:img','xpath:attributes', 'xpath:href', 'dom:index', 'xpath:position'];
change it the way you want (not all of them has to be there)
see:
chrome://selenium-ide/content/locatorBuilders.js
save as your_file.js
add your_file.js as "Selenium Core extensions" in the IDE options
Firefinder for Firebug helps matching both CSS and XPath locators
In general, with Firebug installed, you can Inspect Elements for their HTML and DOM structures to determine what best locator you can build.
the best way to find x PAth is :
open developer tool bar in chrome:
Find the x Path displayed below :
You can directly copy and paste this x path in your script