Storing values in Selenium IDE with a non standard tag - selenium

I have a non standard tag in an HTML doc that I need to write a selenium test for.
Here is the tag: <evo:password>SomeText</evo:password>
And my selenium ide command I'm trying:
Command: storeEval
Target: xpath=/x:html/x:body/x:div/x:div[1]/x:div[2]/x:div/x:div/x:table/x:tbody/x:tr[2]/x:td[2]/x:strong/x:evo:password
Value: adminPass
Not sure what I need as my Target to get this to work and store the value between my tags.

I had to get creative with my selector. I ended up using a CSS selector and getting the last element with it.
css=strong:last
I'm sure you can also use :nth-child among other natural css selectors.

Related

Does selenium IDE have a way to handle dynamic elements?

I was using selenium IDE to automate testing on a web page that has dynamic xpath in it.
I noticed selenium IDE was capturing the xpath fine the first time playing it. Then after closing the browser and opening, of course the xpath has changed, but the target saved was the old xpath.
Is there a way to handle this in selenium?
I know I can use the .contains method but can i apply that to the target?
Picture of selenium IDE firefox extension
To identify the dynamic elements you can construct dynamic locators. As couple of examples:
Using a css for a <span> tag with id attribute starting with abc:
span[id^='abc']
Using a css for a <span> tag with class attribute containing pqr:
span[class*='pqr']
Using a xpath for a <span> tag with value attribute ending with xyz:
span[value$='xyz']
Using a xpath for a <span> tag with id attribute starting with abc:
//span[starts-with(#id, 'abc')]
Using a xpath for a <span> tag with class attribute containing pqr:
//span[contains(#class, 'pqr')]
Explanation of the dynamic CSS_SELECTOR
The wildcards are defined as follows:
^ : To indicate an attribute value starts with
* : To indicate an attribute value contains
$ : To indicate an attribute value ends with
References
You can find a couple of relevant detailed discussions in:
Java Selenium webdriver expression finding dynamic element by ccs that starts with and ends with

Selenium css selectors on element with huge list of classes

I've been working on automation of a product that uses Dojo. The html I'm working with is very messy.. I need to click on div that has following css selector
div.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox.dijitComboBox.dijitDateTextBox.dijitValidationTextBox.dijitTextBoxError.dijitComboBoxError.dijitDateTextBoxError.dijitValidationTextBoxError.dijitError
I'm using firefinder plugin in Firefox and it can see the element all the time, out of 2 chrome plugins I have (CSS selector tester and CSS and Xpath checker) only the first one can find the element.
When I run my selenium code I get org.openqa.selenium.NoSuchElementException.
I tried selecting classes with . and with [class=".."] as well and both failed.
Is there some selenium limitation on how many classes you can have assigned to your element before it stops seeing an element? What stable approach can I use to make my tests work?
Use FirePath plugin in firefox and look for unique classes so you only have 1 unique selector. Also look up CSS selectors, they will help you in the long run
http://www.w3schools.com/cssref/css_selectors.asp

Using Selenium IDE, how to test CSS style information

I am testing a plugin which makes changes to the CSS of HTML elements – how can I use Selenium commands to verify/test these CSS changes?
You can use CSS classes and then check if the element has a specific class.
In Selenium IDE :
Command: assertAttribute
Target: document.getElementById('header')[0]#class
Value: myHeader
Unfortunately Selenium IDE is mis-sold as a Record and Replay tool. Selenium IDE is actually a record, tweak and replay tool.
The tweak part is because the IDE can't record everything that you want. I recommend that you create your test from scratch by hand to get it to check the elements CSS.

Is there a way to store in a variable the text in a certain element in selenium?

I have a selenium script that I created with Selenium IDE. I was
wondering if there is anyway to store the text that is in a certain
element in a variable so that I can use that text later in the script? I am using selenium IDE to do it and then importing it into browsermob.
For Example: I have this html:
<div id=title>
<h2>Website</h2>
<h3><span>web app</span>www.google.com</h3>
</div>
The text in the h3 (www.google.com) changes with different pages. I want a script to be able to run on all these pages that grabs the text in the h3 (in this case www.google.com), and stores it in a javascript variable which I can use in a later part of the script.
http://seleniumhq.org/docs/04_selenese_commands.html#store-commands-and-selenium-variables
Depending what exactly you are trying to do, the storeEval command may be of use. You should just be able to start the Xpath with // as the argument to the storeEval command (so that Selenium knows that you are referencing an Xpath rather than, say, a DOM element).
see How do you store an elements text with selenium in a javascript variable?
You can use the following piece of code for your task. It will work.
storeEval window.document.getElementById('menuless') varname
echo varname

Selenium xpath flow

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