How could i fill fields of pop up windows with Selenium? - selenium-ide

I'm working with Selenium extension for Firefox trying to fill fields for one project of the university for Facebook but I can not access to a specific window (promote website) on a page created by me on that social network, because appears an error with the following message:
Element id = fbpage.... not found
I don't know if it's because this is a pop up window or something similar.
Someone knows how could I access to that kind of field?
I add the html code version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.facebook.com/admgsproject" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Facebook</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Facebook</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=#navItem_811212168953432 > div > div.clearfix > a._5afe.sortableItem > div.linkWrap.noCount > span</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=#navItem_811212168953432 > div > div.clearfix > a._5afe.sortableItem > div.linkWrap.noCount > span</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=fbpage_invite_audience_action</td> //ERROR
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=fbpage_invite_audience_action</td> //ERROR
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[#id='u_jsonp_3_2']/div/ul/li[3]/a/span/span</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[#id='u_jsonp_3_2']/div/ul/li[3]/a/span/span</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
The part where i can not access is the html code that have invite_audience_action
Thank you in advance!

Have you looked into the selectWindow command?
https://saucelabs.com/resources/selenium-tips-working-with-multiple-windows

Related

spring mvc and freemarker - how to post a form ?

I am unsure about doing simple crud operation with spring and freemarker.This is what I tried to do.
springTag.ftl
<!DOCTYPE html>
<html xmlns:sec="http://www.springframework.org/security/tags" >
<head>
......
<#import "/spring.ftl" as spring />
..........
<head>
......
</head>
<body>
<#fragment.header/>
<form action="/listController/springTag" method="post" >
<#spring.bind "student" />
<table>
<tr>
<td>Name:</td>
<td><input path="student.name" /></td>
</tr>
<tr>
<td>Age:</td>
<td><input path="student.age" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Save Changes" />
</td>
</tr>
</table>
</form>
........................
</body>
How do I get the values in controller ? I have specified the model attribute as student . I am a newbee here . Can someone help ?
I found the answer.
<form action="/listController/springTag" method="post" >
<#spring.bind path= "student" />
<table>
<tr>
<td>Name:</td>
<td> <#spring.formInput "student.name" /> </td>
</tr>
<tr>
<td>Age:</td>
<td><#spring.formInput "student.age" />
<#spring.showErrors "student.age","error" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Save Changes" />
</td>
</tr>
</table>
</form>
This was the change I made.

Selenium IDE test duration

I was wondering how I can get an echo of the duration of a test.
I already got the time stamp at the beginning of the test and at the end, but for the reason of laziness it would be nice to get an echo displaying the time it took to run the test.
Here is the code that works on my side. It displays 5 sec duration (pause in test). Try it yourself:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.google.com.ua/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>storeEval</td>
<td>{new Date()}</td>
<td>Cur_time</td>
</tr>
<tr>
<td>echo</td>
<td>${Cur_time}</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>{new Date()}</td>
<td>Cur_time2</td>
</tr>
<tr>
<td>echo</td>
<td>${Cur_time2}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>{(storedVars["Cur_time2"].getTime() - storedVars["Cur_time"].getTime())/1000}</td>
<td>diff</td>
</tr>
<tr>
<td>echo</td>
<td>${diff}</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
storeEval is your friend here.
I'm assuming you have the start and end timestamps stored in variables, so you can storeEval end-start and echo the result

How to enter text in TinyMCE editor with Selenium IDE in firefox 14

I made a test which is working in newer or older firefox versions, slower or faster internet connection (at least I say that internet of my virtual machine in vmware is slow), but something and I don't know what causes a failure after typeKeys command in another computer. Somehow text is not written in the TinyMCE editor and therefore assertion fails.
Can anyone tell me what could cause such a thing or maybe there are incompatible commands?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://tinymce.com" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>http://tinymce.com/tryit</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>15000</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=demo_tab</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>id=content_ifr</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>id=content_ifr</td>
<td></td>
</tr>
<tr>
<td>focus</td>
<td>//body[#id='tinymce']</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//body[#id='tinymce']</td>
<td>(1,1)</td>
</tr>
<tr>
<td>typeKeys</td>
<td>//body[#id='tinymce']</td>
<td>writing something in this silly form</td>
</tr>
<tr>
<td>fireEvent</td>
<td>//body[#id='tinymce']</td>
<td>blur</td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>writing something</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>relative=parent</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=submitbtn</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=submitbtn</td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Post dump</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>HTML output from post</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>writing something</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Don't hesitate to ask if I wasn't clear enough.
Thanks for replies in advance.
Try using
Command | runScript
Target | tinyMCE.get('text_area_id_not_iframe_id').setContent('Your text')
Which will work on specific tinyMCE's or if you have multiple tinyMCEs on one page
Otherwise if you only have one tinyMCE, runScript | tinyMCE.activeEditor.setContent('Your text')
Here's what's working for me, essentially, by selecting the frame (others have suggested this), then the click and focus commands will make it the active editor, allowing the sendKeys command to work. In this example, I'm passing a variable to the editor as well as saving the iframe TinyMCE creates as a variable. For instances where multiple, I'm looping through them based on the ${frame} variable.
<
tr>
<td>selectWindow</td>
<td>null</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>xpath=//*[contains (#id, '${frame}')]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td></td>
</tr>
<tr>
<td>focus</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td></td>
</tr>
<tr>
<td>sendKeys</td>
<td>xpath=//*[contains (#id, 'tinymce')]</td>
<td>${date} ${frame}</td>
</tr>

Handling search button using iPhone browser?

I'm developing a web application in asp(mobile).
When using the iPhone browser for entering some search text in the search text box (<mobile:TextBox ID="txtSearchData" Runat="server" BreakAfter=False></mobile:TextBox>) , the iPhone launches the search keypad and when I click the search button using the iPhone keypad it refreshes the full page, but clicking the search button below the textbox it is working fine.
Can anyone tell me how to fix this?
Here's my code so far:
<body>
<mobile:Form ID="frmSearch" Runat="server" Font-Name="NotSet" Font-Size="Small">
<mobile:DeviceSpecific ID="dsSearch" Runat="server">
<Choice Filter="isHTML32">
<ScriptTemplate>
<link href="StyleSheets/Common.css" rel="stylesheet" type="text/css"></link>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta id="Meta1" name="viewport" content="width=device-width; initial-scale=1.0;" />
</ScriptTemplate>
<HeaderTemplate>
<table cellspacing="2" width="100%">
<tr>
<td width="100%">
<uc1:Header ID="ucHeader" runat="server" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td align="right">
Find :
</td>
<td>
<mobile:DeviceSpecific>
<Choice="isHTML32">
<ContentTemplate>
<asp:DropDownList ID="lstGroups" runat="server" OnSelectedIndexChanged="LstGroups_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</ContentTemplate>
</Choice>
</mobile:DeviceSpecific>
</td>
</tr>
<tr>
<td align="right"> Search by:</td>
<td>
<mobile:SelectionList ID="lstSearchPreferences" Runat="server" BreakAfter=False>
<Item Selected=True Text="select" />
</mobile:SelectionList>
</td>
</tr>
<tr>
<td> </td>
<td>
<mobile:SelectionList ID="lstSearchOptions" Runat="server" BreakAfter=False>
</mobile:SelectionList>
</td>
</tr>
<tr>
<td> </td>
<td>
<mobile:TextBox ID="txtSearchData" Runat="server" BreakAfter=False>
</mobile:TextBox>
</td>
</tr>
<tr id="trContractorFilter" runat="server" visible="False">
<td align="right">
<mobile:Label id="lblContractorFilter" BreakAfter=False Runat="server" Visible="True" >
Results:
</mobile:Label>
</td>
<td>
<mobile:SelectionList ID="lstContractorFilter" Runat="server" BreakAfter="True" Visible ="True" >
<Item Selected="True" Text="Active Permits" />
<Item Text="All Permits" />
</mobile:SelectionList>
(your permits only)
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2" align="center">
<mobile:DeviceSpecific>
<Choice="isHTML32">
<ContentTemplate>
<asp:Button ID="btnSearch" runat="server" Text="Search" UseSubmitBehavior=true OnClick="BtnSearch_Click"/>
</ContentTemplate>
</Choice>
</mobile:DeviceSpecific>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<mobile:Label ID="lblError" Runat="server" Font-Bold="True" ForeColor=Red Visible="false" BreakAfter=False></mobile:Label>
</td>
</tr>
</table>
</HeaderTemplate>
</Choice>
</mobile:DeviceSpecific>
</mobile:Form>
</body>
In conjunction with this question and its answer using jQuery, you can write this same code in your page and do the client processing before firing the submit.
Additionally, you can use $.ajax() library functions to submit the form asynchronously(within the above discussed code block and not firing the form.submit() at all), which will eliminate any page refresh (no matter from where the form submit event is fired.)
<form id="hello-world" action="sayhello">
<input type="submit" value="Hello!">
</form>
You can attach an event handler like this:
$('#hello-world').submit(function(ev) {
ev.preventDefault(); // to stop the form from submitting
/* Validations go here */
//this.submit(); // If all the validations succeeded
$.ajax({
url:'your_form_target',
data:formData,
success:function(data,textStatus, jqXHR){
}
});
});
Set the Action attribute of mobile:Form to #.
That should cancel the default postback action of the form, which is executed when the Search button on the keyboard is hit.
Ref
By default ASP.NET controls make full page postback, to send page data to the server.
For handling AJAX request on asp.net you should use an ScriptManager and UpdatePanel controls or using a client side mechanism like jQuery AJAX.
The reason is that your search BUTTON isn't actually firing the form submission, it's firing a JS function: onClick="BtnSearch_Click"
BtnSearch_Click is probably preventing the default action (Submitting the form and reloading the page) from occurring which is what you need to do to your form's default submit action.
I'm not familiar with ASP, so i'm probably way off the mark but you should be able to put a
onSubmit="Btn_Click"
on the form, which the "search" button on iOS will trigger.

Struts 2 select tag filled by list property

I am new to struts 2. I am facing problem in filling Select tag with list property. The values are supplied from action class.Please provide me sample sode for this scenario.
My action class
public class TripDetailsAdd extends ActionSupport {
#Override
public String execute() throws Exception {
return SUCCESS;
}
public String populate() {
VehicleDAO vehicleDAO = new VehicleDAO();
this.lstVehicles.addAll(vehicleDAO.getAllVehicles());
return "populate";
}
private String vehicleId;
private Collection lstVehicles = new ArrayList<VehiclesVO>();
}
Jsp page content:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sform" uri="/struts-dojo-tags"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#page import="com.vms.business.dao.VehicleDAO"%>
<%#page import="java.util.Collection"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Trip Details</title>
</head>
<body>
<s:form action="tripDetailsAdd" method="POST" >
<s:hidden name="expenseTypeId"></s:hidden>
<table width="100%" height="96%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><!-- Menu Starts --> <jsp:include
page="/pages/menu.jsp"></jsp:include> <!-- Menu End -->
<table width="95%" align="center">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="highlight">Trip Details Add</td>
<td><s:actionerror /><s:actionmessage /></td>
</tr>
<tr>
<td class="header3shadow" colspan="2"><img height="2"
border="0" width="100%"></img></td>
</tr>
</table>
<table>
<tr>
<td> </td>
</tr>
</table>
<div
style="overflow: auto; height: expression((document.body.clientHeight -80) +px ');">
<table width="60%" cellspacing="0" cellpadding="0" border='0'>
<tr>
<td class="FieldTitle" valign="top">
<table width="100%" cellspacing="4" cellpadding="0" border='0'>
<s:select headerKey="0" headerValue="Select One" required="*" label="Vehicle No."
labelSeparator=":" list="lstVehicles" listKey="vehicleId" listValue="regNo"></s:select>
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="4" cellpadding="0" border='0'>
<s:textfield labelposition="left" requiredposition="right"
name="totalIncome" label="Total Income" cssStyle="FieldTitle"
labelSeparator=":"></s:textfield>
</table>
</td>
</tr>
</table>
<table cellpadding="0" width="60%" cellspacing="0" border="0">
<tr>
<td align="right"><s:submit label="Add" value="Add"></s:submit></td>
</tr>
</table>
</div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</s:form>
</body>
</html>
Mapping
<action name="*TripDetailsAdd" method="{1}"
class="com.vms.trip.presentation.TripDetailsAdd">
<result name="success" type="redirect">showTripDetailsList
</result>
<result name="populate">/pages/tripdetails/TripDetailsAdd.jsp
</result>
<result name="error">/pages/tripdetails/TripDetailsAdd.jsp
</result>
<result name="input">/pages/tripdetails/TripDetailsAdd.jsp
</result>
</action>
In this if i add Validation file or If any error occurs in page drop down is not loading.Please help me..
Struts2 select tag
<s:select label="Pets"
name="petIds"
list="petDao.pets"
listKey="id"
listValue="name"
value="%{petDao.pets.{id}}"
/>
In the above. value = default selection, list = collection (of Map) coming from your action class, listKey = Key for map, listValue = value for map.
Edit (after looking at provided code):
your problem is that you do not have any getter in action class that corresponds with lstVehicles (which is mentioned in list property of your select tag)
Add this to your action class:
public List getLstVehicles ()
{
return this.lstVehicles;
}