How to get an integer on selenium IDE - selenium

I got this page where I want to run my code:
I got a css with this properties:
<center>
Radicacion Exitosa, Numero Radicacion: 12 - 132263…
</center>
I want to store the "132263" in a variable because I have to copy and paste them in another window, so I want to know if there is a way to only get the number from that tag...specially the "132263" because if I store a Variable Selenium IDE only will get the full text.
Thanks

Using regex in javascript will do this for you:
<tr>
<td>storeText</td>
<td>//center</td>
<td>full</td>
</tr>
<tr>
<td>storeEval</td>
<td>var regex=/\-\s+(\d+)\s+\-/;regex.exec(storedVars['full'])[1];</td>
<td>number</td>
</tr>
<tr>
<td>echo</td>
<td>${number}</td>
<td></td>
</tr>
We're capturing the text from the CENTER tag and then running the regex to grab the number out of it (using the group (\d+) and returning [1]).

Related

captureEntirePageScreenshot with dynamic name in Selenese

I want to generate the filename parameter of the captureEntirePageScreenshot command in Selenese through javascript. Is that possible?
The scenario is that I want to take a screenshot of every page that is opened, and the name of the webpage is generated dynamically and encodes some information.
Combine it in javascript:
<tr>
<td>storeEval</td>
<td>Date.now()</td>
<td>timestamp</td>
</tr>
<tr>
<td>storeEval</td>
<td>"SomePrefixScreenShot" + storedVars['timestamp']</td>
<td>filename</td>
</tr>
<tr>
<td>echo</td>
<td>${filename}</td>
<td></td>
</tr>
This can be done by using the "storeEval" command to generate the name, followed by the original "captureEntirePageScreenshot" command that uses the variable defined in "storeEval" as the parameter.
I hope it saves someone 30 mins :)

storeAttribute or storeElementPresent?

I am hoping I can get some help, I need to know how to accomplish something but not sure how as I am new to selenium commands.
I tried the following:
storeEval
javascript{window.document.getElementById('myDiv');}
myResult
then
gotoIf
${myResult} == false
lblWhereToGoIfStyleDisplayIsNotVisible
This does not give me what I want as I always have the div in my page, even if the style = display : none.
What I need is to get the display property of the style of the div and check that value to see if none to then jump to the lblWhereToGoIfStyleDisplayIsNotVisible label
I was thinking I need to use storeAttribute or storeElementPresent but not sure how to implement properly to get result needed.
Any help is appreciated, thanks in advance.
I finally got my script working on my own as I was getting no quick responses, I tried many other type of searches about the gotoIf, css attributes, etc... and found one link at
http://sysmagazine.com/posts/190358/
which helped alot...
here is the final code if someone is interested in knowing how to get a div, display property value, store it, compare it to == NONE (if div is hidden) and go to the next label (test location in the script) in order to continue testing (setting dropdown values)....
this allows me to set values only if the div exists and is visible meaning the dropdown will have selections
This allowed me also to define 1 script for multiple possible test cases, just by changing the url based on the test I want to have.
Cheers!
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>window.getComputedStyle(window.document.getElementById('trProtection'),null).getPropertyValue('display');</td>
<td>myResult</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{storedVars['myResult'];}</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['myResult'] == "none"</td>
<td>lblDivision</td>
</tr>
<tr>
<td>select</td>
<td>id=selProtection</td>
<td>label=DISABILITY</td>
</tr>
<tr>
<td>label</td>
<td>lblDivision</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>

Can't used Stored Variables in Selenium IDE

I use Selenium IDE to make some test.
When I store variable like this :
<tr>
<td>store</td>
<td>RandomProductRef</td>
<td>XXX</td>
</tr>
I can't use it sometimes like this :
<tr>
<td>type</td>
<td>css=#ctl00_ctl00_ContentPlaceHolder2_ChildPlaceHolder2_txtSearch</td>
<td>${RandomProductRef}</td>
</tr>
It type ${RandomProductRef} in the input...
I've used the same way for an auth form and its works
Someone know why ?
Thanks
You should set variable name to the value input of Selenium IDE:
<tr>
<td>store</td>
<td>XXX</td>
<td>RandomProductRef</td>
</tr>
Then
<tr>
<td>echo</td>
<td>${RandomProductRef}</td>
<td></td>
</tr>
gives XXX
The only reason I could see that not working, is because your selector #ctl00_ctl00_ContentPlaceHolder2_ChildPlaceHolder2_txtSearch might be invalid at the time of execution.
Make sure that that element is present at the time of executing your type action, and that should work.
You should change the first command to save the text "XXX" to the variable "RandomProductRef".
<tr>
<td>store</td>
<td>XXX</td>
<td>RandomProductRef</td>
</tr>
<tr>
<td>type</td>
<td>css=#ctl00_ctl00_ContentPlaceHolder2_ChildPlaceHolder2_txtSearch</td>
<td>${RandomProductRef}</td>
</tr>

Parsing a number using Selenium IDE

I got in my site several amounts of money displayed like this: $5,000
I want to sum all of them and to check some variables. How can I parse and get the number 5000 and use it as a number (summing up, multiplying etc) using Selenium IDE?
You can use storeEval and parse the string into the Number using javascript:
<tr>
<td>storeEval</td>
<td>Number('$5,000'.replace(/[^0-9\.]+/g,""));</td>
<td>amount</td>
</tr>
<tr>
<td>echo</td>
<td>${amount}</td>
<td></td>
</tr>

How to get xpath from "Page Should Contain" in a web page using RobotFramework and Selenium

I'm writing test cases for a webpage that has a table as the main focus of the page. I'm checking that the page contains a new entry via the Page Should Contain fucntion, I then want to find the xpath for this element. I am doing this because each entry is added to the end of the table so I cannot set a static xpath for it because I don't know how many entries will be added between each run of this particular test.
Thanks in advance.
<table class="fw-table">
<thead>
<tr class="affix-header">
<th class="columnwidth-description">Email</th>
<th>Account</th>
<th>Signed up</th>
<th>Number of invalid attempts</th>
</tr>
</thead>
<tbody>
<tr>
<td>devtest</td>
<td>Account</td>
<td>true</td>
<td>0</td>
</tr>
<tr>
<td>test#testing.com</td>
<td>Account</td>
<td>true</td>
<td>1</td>
</tr>
search for: xpath=//body/div[2]/div/div[2]/div[2]/div/div/table/tbody/tr[1]/td[1]
If you need to verify that last table row contains certain text you can use the Page Should Contain Element keyword and provide an xpath locator which will find the last table row containing your text:
Page Should Contain Element xpath=//table[#class="fw-table"]//tr[last()]//td[contains(text(),'bottomline')]