Selenium - Store iframe:src - selenium

I have a webpage which contains an iframe such as this
<iframe src="iframe_src" style="border: none" scrolling="no" id="id_frame" width="100%" frameborder="0" height="1850">...</iframe>
I'm trying to storeText the iframe src attribute, but executing the following command won't do the trick:
storeText //iframe[#id='id_frame']//#src frame_src
I expect frame_src to be equal to "iframe_src"
How can I do it?
Thanks!

I expect frame_src to be equal to "iframe_src"
First off, storeText will store the innerHTML of your target. What you want, is the storeAttribute command, however we can simplify it using the verifyAttribute command.
Command | Target | Value
============================================================
verifyAttribute | //iframe[#id='id_frame']#src | frame_src

Related

Getting value from div which contains exact string using Selenium IDE

I am trying to get a value from a nested div in a web page using Selenium IDE where class names are repeated but contain unique strings, such as the structure below, but am having no luck.
<div class='ClassName'>
<div class="col_Num">1 </div>
<div class="col_Val">5.00 </div>
</div>
<div class='ClassName'>
<div class="col_Num">2 </div>
<div class="col_Val">2.00 </div>
</div>
How do I get the value of 'Col_Val' from only the div that contains "col_Num = 1"? (the value 5.00 should be returned and saved to a variable)
Thanks,
J
From your question, it seems that you want to be able to store the column value based on the number you input. The best way to do this would be
<tr>
<td>storeText</td>
<td>css=div:contains("1")+[class=col_Val]</td>
<td>value</td>
</tr>
Which will store the column value located immediately after the div containing the value you input (in this case 1)
In Selenium IDE enter as: Command | Target | Value
storeText | //div[#class='col_Num' and contains(text(), '1')]/following-sibling::div | value
echo | ${value}
Output is:
[info] Executing: |storeText | //div[#class='col_Num' and contains(text(), '1')]/following-sibling::div | value |
[info] Executing: |echo | ${value} | |
[info] echo: 5.00
[info] Test case passed

Selenium IDE: Selenium script execution stops at the first missing link

I use Selenium IDE to test some webpage content.
My problem is: I have a test case with several 'clickAndWait' instructions on different links. Some links are missing on the webpage. My test case stops at the first missing link. I need my test case to be executed entirely even if a link is missing.
Example:
open | myurl.com |
clickAndWait | mainLink |
clickAndWait | minorLink1 |
verifyTextPresent | text1 |
clickAndWait | mainLink |
clickAndWait | minorLink2 |
verifyTextPresent | text2 |
clickAndWait | mainLink |
clickAndWait | minorLink3 |
verifyTextPresent | text3 |
The problem is, if minorLink1 does not exist, the whole test case is stopped, but I need minorLink2 and minorLink3 to be tested.
Does anyone can help me?
Thanks by advance,
Thomas.
Within the IDE you will not be able to run this as one test if you want it to continue, as the IDE simply follows the instruction order and has to stop when an instruction breaks. You could separate these into separate tests within the IDE, or you could move the operation to one of the supported environments like Java or C#, where you could write logic to avoid a full stop.
You could use loops which I have found to be very effective with ever changing lists where data can start on page one but end up on any page.
Or you could use gotoif command which would look something like this:
<tr>
<td>storeElementPresent</td>
<td>${category_header_obj}</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['present']==false</td>
<td>exit</td>
</tr>
<tr>
<td>verifyText</td>
<td>${category_header_obj}</td>
<td>Categories</td>
</tr>
<tr>
<td>Label</td>
<td></td>
<td>exit</td>
</tr>

Selenium finds element only when I manually click Execute

I need to click on the button automatically. Code:
<tr>
<td>click</td>
<td>css=button</td>
<td></td>
When I click "Play current test case" it does not finds the element. But when I click "Find" after that - it does, and if I click Execute - it clicks on it!
Log:
[info] Executing: |click | css=div.sometag > p | |
[info] Executing: |pause | | 2000 | // Same error with pause & without it
[info] Executing: |clickAndWait | css=button | | // Auto executing
[error] Element css=button not found // Fails
[info] Executing: |click | css=button | | // I click on "Execute" manually - OK!
Why?
Have you tried to insert "waitForElementPresent|css=button|" before the click statement? This might help.
You actually need to use the class selector. So either div.button or .button, otherwise selenium probably is looking for an ID or an element name.
You could also try using a different type of locator, such as ID or XPath.
If we were able to see the HTML of the page you are interacting with, we could provide exact examples.

selenium rc server does not exit after running an htmlsuite

Am I missing something obvious? The docos state that:
-htmlSuite : Run a
single HTML Selenese (Selenium Core) suite and then exit
immediately ...
but my instance doesn't seem to (it also doesn't write to the html output either)
I am running : java -jar /opt/selenium-server-1.0.3/selenium-server.jar -debug -htmlSuite *googlechrome http://www.google.co.uk ~/tsg1.ts ~/g.out
I have also given up trying to put xml into this editor - but all I am doing is opening www.google.co.uk and looking for "about google" - which works fine in the firefox ide, but never exits on RC... Any ideas ?! The same happens with *firefox as well :-(
Ok - I dug around and found the following.
The selenium IDE generates an ERRONEOUS line in the "heading" which somehow breaks the -htmlsuite option (ie it never exits). Comment the line out as per this example :
`
< table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium" >
< tbody >
< !-- < tr >< td >< b > Test Suite< / b >< /td >< /tr > -- >
< tr >< td >< a href="test_case_google" >test_case_google< /a >< /td >< /tr >
< /tbody >< /table >
< /body >
< /html >
`
Try with quotes:
java -jar /opt/selenium-server-1.0.3/selenium-server.jar -debug -htmlSuite '*googlechrome" "http://www.google.co.uk" "~/tsg1.ts" "~/g.out"
I only have this problem with firefox. Running with chrome seems to work fine.
If you do what Richard Green suggests you only get to run one test (the last one it seems). The "Test Suite" line tells selenium that it is a test suite and needs to run all the tests present.
So the problem seems to be that in firefox at least it wont jump from test to test when running a test suite.
For firefox if you do what is described in this issue: https://code.google.com/p/selenium/issues/detail?id=1759 it works. Chrome works too.
If by any chance the link doesn't work the workaround is to remove the first two lines of the files:
... yanked out the first two lines of each file. The ones starting with:
xml version...
DOCTYPE html PUBLIC...
You "must" save all your html test with ".html" extension and reference them in testSuit.html with the ".html" extension.
So, instead of:
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>test_case_google</td></tr>
</tbody>
</table>
It "must" be:
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>test_case_google</td></tr>
</tbody>
</table>

Parsing URL for querystring values with Selenium IDE

I'm new to integration testing, but have had great success so far buiding up a suite of tests using Se:IDE. As I've been running my tests, it has occurred to me that I'm generating a substantial amount of data and I'd like to clean up after myself.
Most of my tests involve creating a new 'page', and the id is available in the querystring. I'd like to have Se:IDE store a querystring value and pass it to another page that calls a delete method to tidy up after I have run my verifications.
I see that I can use the command storeLocation, but I'm not sure how I would go about parsing that value for the id in the querystring, and then pass it to another page using Open.
Have I reached the point where I need to migrate my tests to c#, or is this possible using the IDE?
If you keep all your test cases inside the same test suite. They can share variables between executions without problems.
So, all you have to do is to store the desired value:
storeLocation | variable | |
and in a future test, you have to use the variable as the following:
open | ${variable} | |
Note: for more info on test suites, take a look at:
http://seleniumhq.org/docs/03_selenium_ide.html#writing-a-test-suite
Update:
You can now use javascript regular expressions to get a substring from a variable:
storeEval | reg = /substring pattern/;reg.exec(${variable}) | substring
open | ${substring} | |
Example:
store | "012la4la" | a
storeEval | re = /[0-3]*la/;re.exec(${a}) | new
echo | ${new} |
output:
[info] echo: 012la
I had a similar issue at work, and this Q&A blog helped me out a lot. In my case, I had to strip query string parameters from an aspx URL, and verify their existence.
And I used a 2 stage filter approach for verification
(1) storeLocation, storeEval and verifyExpression.
(2) verifyHTMLsource and globbing the string
<tr>
<td>verifyLocation</td>
<td>http://qa.clockstock.com/confirmation.aspx?exrc=90210&csrc=</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>urlconf</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${urlconf}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['urlconf'].indexOf('exrc=90210');</td>
<td>exrcurlconf</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>javascript{(storedVars['CIDurlconf']>0)}</td>
<td>true</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['urlconf'].indexOf('csrc=');</td>
<td>CSRCurlconf</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>javascript{(storedVars['CSRCurlconf']>0)}</td>
<td>true</td>
</tr>
<tr>
<td>verifyHtmlSource</td>
<td>glob:*confirmation.aspx*exrc=90210*csrc=*</td>
<td></td>
</tr>
A quick example for extracting an id parameter from a query string would be:
storeLocation | myLocation
store | javascript{ storedVars['myLocation'].substring(storedVars['myLocation'].indexOf('id=')+3, storedVars['myLocation'].length); } | idValue
This assumes that the id parameter is the last in the query string. If it's not then you might be best splitting the location on '&' and looping through the resulting array for the 'id' parameter value.