How can I create a variable that has the id from one of my records on the index page?
I can use xpath to get at the anchor I want with:
storeText
//table[#id='districts']//tr/td/a[text()='Fairview Union']
id_of_another_district
but that gets the link name. I want to id for that record, i.e. in the original source code I have:
<tr>
<td>
Fairview Union
<span class='small'>(Select)</span>
</td>
<td></td>
<td></td>
<td></td>
<td class='rightalign'>01/09/2012</td>
<td></td>
<td></td>
<td><img alt="Delete" src="/assets/icons/delete-a77f3c3c125b0817085648f284c98938.png" /></td>
</tr>
and what I want to get and store in a variable in selenium is the record number 31
Using the 'store' command, you can execute javascript code in the 'target' column...
store | javascript{...} | myVar
where the ... is, substitute it with the js you need to return the id.
[Edit from Michael]
I ended up using:
storeAttribute | //*[#class='small']/a[text()='(Select)']/#href | hrefAttr
store | javascript{storedVars['hrefAttr'].replace(/.*\//,'')} | myVar
echo | ${myVar}
myVar now has the ID and I can do things like:
open
/users/change_district/${id_of_another_district}
The answer of sircapsalot (edited by Michael Durrant) is ok, but it's a bit different in my environment, regarding how the javascript is executed: not with javascript{...} So, in my case it looks like this and it works fine:
<tr>
<td>storeAttribute</td>
<td>//html/body/table/tbody/tr[3]/a#href</td>
<td>hrefAttr</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['hrefAttr'].replace(/.*=/,'')</td>
<td>transportIdVar</td>
</tr>
<tr>
<td>echo</td>
<td>${transportIdVar}</td>
<td></td>
</tr>
The href in my case looks like this:
http://example/local/IntegrationPick?partyId=8080595
Related
My HTML code looks like:
Table 1: And Table 2
<table id="ContentPlaceHolder_Body0">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
<table id="ContentPlaceHolder_Body1">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
When I use //*[contains(text(),'Some Name')] this xpath selects 2 values while I need to select only one value by Text.
I need to use that xpath with Text.
I'm trying to create xpath to get the "Some Name" from Table 2, element locator by using Text.
So I created this Xpath:
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
This xpath is not working, need help to create correct xpath.
Given your HTML, this XPath works for me
//table[#id='ContentPlaceHolder_Body1']//td[text()='Some Name']
I think the issue with your XPath is that you were using #text() when it should be text().
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
^ remove the #
You need to just remove the #
//table[#id='ContentPlaceHolder_Body1']//tr//td[text()='Some Name']
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>
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]).
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>
i have stuck in one point in selenium ide
the scenario is like this
Login-----
go to dashboard page---------
mouse over any menu on the top navigational bar----
on mouseover sub menu will appear as drop down--
now click any link from the drop down --
after clicking link will open in new tab
now from that point on-wards we have to shift our focus to that new tab because rest of the testing will be done on that new tab.
The code i have written is given below
<tr>
<td>open</td>
<td>/magma/dev/</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=user_id</td>
<td>abcd</td>
</tr>
<tr>
<td>type</td>
<td>name=pass</td>
<td>1234</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=btnLogin</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Costing List</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Fuel</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>//div[#id='smoothmenu1']/ul/li[3]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Fuel Cost</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>http://10.0.1.101/magma/dev/fuelcost/</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Manage Fuel Cost</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Logout</td>
<td></td>
</tr>
This code is working correctly upto clicking the sub menu from the dropdown after that it is not working and a error is showing in the log
so when ever i am trying to run that test case it is showing error
[warn] Link has target '_blank', which is not supported in Selenium! Randomizing target to be: selenium_blank84419
can any one please help me to write the code properly
The following code works for me:
<tr>
<td>storeEval</td>
<td>selenium.getAllWindowNames()[1]</td>
<td>windowName</td>
</tr>
<tr>
<td>getEval</td>
<td>this.doEcho("array length: "+selenium.getAllWindowNames().length);this.doEcho("Available window names: "+selenium.getAllWindowNames());this.doEcho("Selecting window: "+storedVars['windowName']);</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>${windowName}</td>
<td></td>
</tr>
I hope it will help others who face a similar type of problem
use selectPopUp, but not storeEval and selectWindow, both of them are too complicated.
selectPopUp:
Arguments:
windowID - an identifier for the popup window, which can take on a number of different meanings
Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).
If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play.
Otherwise, the window will be looked up considering windowID as the following in order: 1) the "name" of the window, as specified to window.open(); 2) a javascript variable which is a reference to a window; and 3) the title of the window. This is the same ordered lookup performed by selectWindow .
The code below ( selenium script, I copied from the selenium IDE ) indicates the action of:
1.click a 'edit' link
2.wait for 2 seconds ( waiting for the new window opened)
3.focus on the new window
<tr>
<td>click</td>
<td>link=edit</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td>selectPopUp</td>
<td></td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>http://10.0.1.101/magma/dev/fuelcost/</td>
<td></td>
</tr>
Replace <td>http://10.0.1.101/magma/dev/fuelcost/</td> with window ID or window title or window name
Try with option
selectWindow()
Just provide the window title name withing ().
For Ex:
Window Title is Testing, then
command : selectWindow
title : Testing
To know the title of the newly opened window follow the steps:
Go to the new window
Right click->view page source
Press ctrl+F.
Type title and serch.
You will get the title of the new window
I hope this helps someone out there! It worked well for me. You do still get the warning in the log, but the test works.
Please add waitForPopUp and selectPopUp event after clicking the new tab event. It's worked for me.
I am using the following and it works for me, hope it helps! :)
storeEval | this.browserbot.findElement('link=link name').href | myUrl |
open | ${myUrl}
I use storeAttribute incombination with open.
Link: http://www.seleniumwiki.com/software-testing/how-to-solve-the-link-has-target-_blank-which-is-not-supported-in-selenium/
I use it like this:
As an alternative, it's possible to remove the target attribute from the link before clicking it. Here's the code to remove all target attributes from all links on the current page:
<tr>
<td>runScript</td>
<td>Array.from(document.links).forEach(function(link){link.removeAttribute('target')})</td>
<td></td>
</tr>