Actually I am checking the excel values whether they are displayed on the web page Mouse hover menu. The menu includes titles and the menu item links. The menu items in main menu and the sub links are in child menu. When I tried to collect all the links, I am getting them separately by finding with CSS. I want to get all the links in one array. I have used the below commands. Please help me how to get all the elements in one array. The developers code is attached as screen shots :
String AdminRoleAccessfilepath = "D:\\PMC
Automation\\AdminRoleAccess.xls";
FileInputStream AdminRoleFile=new
FileInputStream(AdminRoleAccessfilepath);
Workbook rwb=Workbook.getWorkbook(AdminRoleFile);
Sheet AdminRolesheet=rwb.getSheet("AdminRole");
int submenucolumnsize=AdminRolesheet.getRows();
int menucolumnsize=AdminRolesheet.getRows();
String[] arraysubmenu=new String[submenucolumnsize];
String[] arraymenu=new String[menucolumnsize];
List<WebElement>SubTitlelist =
driver.findElements(By.cssSelector(".child_menu>a "));
List<String> allSubTitleslist=new ArrayList<>();
List<WebElement>Titleslist =
driver.findElements(By.cssSelector("#menu_nav>ul>li>a "));
int submenuui = 0;
for (int a=1;a<submenucolumnsize;a++)
{
arraysubmenu[a] = AdminRolesheet.getCell(1,a).getContents();
//System.out.println(arraymenu[a]);
boolean isthere = true;
for(submenuui=0; submenuui<SubTitlelist.size(); submenuui++)
{
if
(!(arraysubmenu[a]).equalsIgnoreCase
(SubTitlelist.get(submenuui).getText()))
{
isthere = false;
}
else
{
isthere = true;
break;
}
}
if(isthere)
System.out.println("\nThe Sub Menu item in the UI-> "
+arraysubmenu[a]+ " existing on the Web Page" );
else
System.out.println("\nThe Sub Menu item in the UI-> "
+arraysubmenu[a]+ " not existing on the Web Page");
}
int menuui = 0;
for (int b=1;b<menucolumnsize;b++)
{
arraymenu[b] = AdminRolesheet.getCell(1,b).getContents();
//System.out.println(arraymenu[a]);
boolean isthere = true;
for(menuui=0; menuui<Titleslist.size(); menuui++)
{
if (!(arraymenu[b]).equalsIgnoreCase
(Titleslist.get(menuui).getText()))
{
isthere = false;
}
else
{
isthere = true;
break;
}
}
if(isthere)
System.out.println("\nThe Title in the Menu in the UI-> "
+arraymenu[b]+ " existing on the Web Page" );
else
System.out.println("\nThe Title in the Menu in the UI-> "
+arraymenu[b]+ " not existing on the Web Page");
}
Combine the selectors into one CSS using a comma.
'.child_menu>a , #menu_nav>ul>li>a'
Related
I am trying to understand how sorting works in Table widgets works when loading a page. For most of my pages using the Table widget, the page loads sorted by the first column.
I do see the below code in the onAttach event for the Table panel in a page. I am wondering if this is the code that sets the sorting when a page loads.
// GENERATED CODE: modify at your own risk
window._am = window._am || {};
if (!window._am.TableState) {
window._am.TableState = {};
window._am.inFlight = false;
}
if (!window._am.sortTableBy) {
window._am.sortTableBy = function(datasource, field, fieldHeader, tableState) {
if (!field) {
throw "Can't sort the table because specified field was not found.";
}
tableState.inFlight = true;
if (tableState.sortByField === field.name) {
tableState.ascending = !tableState.ascending;
} else {
if (tableState.fieldHeader) {
tableState.fieldHeader.text = tableState.fieldHeaderText;
tableState.fieldHeader.ariaLabel = "";
}
tableState.sortByField = field.name;
tableState.ascending = true;
tableState.fieldHeader = fieldHeader;
tableState.fieldHeaderText = fieldHeader.text;
}
datasource.query.clearSorting();
var sortDirection = tableState.ascending ? "ascending" : "descending";
datasource.query.sorting[field.name]["_" + sortDirection]();
datasource.query.pageIndex = 1;
datasource.load(function() {
tableState.inFlight = false;
fieldHeader.text = fieldHeader.text.replace(/ (\u25B2|\u25BC)/g, "");
if (tableState.sortByField === field.name) {
fieldHeader.ariaLabel = fieldHeader.text + " sort " + sortDirection;
fieldHeader.text = fieldHeader.text + (tableState.ascending ? " \u25B2" : " \u25BC");
app.accessibility.announce(fieldHeader.ariaLabel);
}
});
};
}
Sorting is set on your datasource.
Click the model (top left) that your table is using.
Click Datasources and expand your Datasource (there will only be one, unless you have created additional ones).
Once you choose the field you want the table to use for sorting, you can choose "Ascending" or "Descending".
The problem is with adding new records from a separate create form. The new records always appear at the end of the list , until a subsequent 'load' is performed.
In the content tree, the structure is as follows
Home
-England
-France
-Germany
There is a sublayout (CommentsForm.ascx), which is used in all the 3 pages. When user browses 'France' and submits a comment, the 'Comment' item should get saved under 'France' and so on..
In this scenario, the Parent item (under which the new item has to be created), is dynamic. So, how to get the parent item in such case. Is this correct?
protected void btnSubmit_Click(object sender, EventArgs e)
{
Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentItem = Sitecore.Context.Item;
string name = "Comment_" + Sitecore.DateUtil.IsoNow;
TemplateItem template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment");
using (new SecurityDisabler())
{
//how to go about here??
//newItem["Author"] = txtAuthor.text;
//newItem["CommentText"] = txtComments.Text;
//parentItem.Add("name", template);
}
}
You can use UserSwitcher safer in production, but you can also use SecurityDisabler using(newSecurityDisabler()){}
Editing and renaming must happen in an Editing.BeginEdit() transaction
Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentItem = Sitecore.Context.Item;
string name = "Comment_" + Sitecore.DateUtil.IsoNow;
var template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment");
using (new Sitecore.SecurityModel.SecurityDisabler())
{
try
{
Item newItem = parentItem.Add("Name", template);
if (newItem!=null)
{
newItem.Editing.BeginEdit();
newItem["Author"] = txtAuthor.text;
newItem["CommentText"] = txtComments.Text;
newItem.Editing.EndEdit();
}
}
catch
{
newItem.Editing.CancelEdit();
}
}
Create items programmatically based on template in sitecore using the simple code
// The SecurityDisabler is required which will overrides the current security model, allowing the code
// to access the item without any security.
using (new Sitecore.SecurityModel.SecurityDisabler())
{
// Get the master database
Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");
// Get the template for which you need to create item
Items.TemplateItem template = master.GetItem("/sitecore/templates/Sample/Sample Item");
// Get the place in the site tree where the new item must be inserted
Item parentItem = master.GetItem("/sitecore/content/home");
// Add the item to the site tree
Item newItem = parentItem.Add("NameOfNewItem", template);
// Set the new item in editing mode
// Fields can only be updated when in editing mode
// (It's like the begin transaction on a database)
newItem.Editing.BeginEdit();
try
{
// Assign values to the fields of the new item
newItem.Fields["Title"].Value = "NewValue1";
newItem.Fields["Text"].Value = "NewValue2";
// End editing will write the new values back to the Sitecore
// database (It's like commit transaction of a database)
newItem.Editing.EndEdit();
}
catch (System.Exception ex)
{
// Log the message on any failure to sitecore log
Sitecore.Diagnostics.Log.Error("Could not update item " + newItem.Paths.FullPath + ": " + ex.Message, this);
// Cancel the edit (not really needed, as Sitecore automatically aborts
// the transaction on exceptions, but it wont hurt your code)
newItem.Editing.CancelEdit();
}
}
using (new Sitecore.SecurityModel.SecurityDisabler())
{
Item newItem = parentItem.Add("Name", TemplateItem.TemplateId);
newItem.Editing.BeginEdit();
newItem.Fields[Constants.IDs.Fields.SicParent.Code].Value = row.SicCode.ToString();
newItem.Fields[Constants.IDs.Fields.SicParent.Description].Value = row.Description;
// this field is a DropList
newItem.Fields[Constants.IDs.Fields.SicParent.Grouping].SetValue(groupItem, true);
newItem.Editing.EndEdit();
}
You can add and item to parentItem and then edit the new item like this:
using (new SecurityDisabler())
{
Item newItem = parentItem.Add("name", template);
newItem.Editing.BeginEdit();
newItem["Author"] = txtAuthor.text;
newItem["CommentText"] = txtComments.Text;
newItem.Editing.EndEdit();
}
I'm using AjaxControlToolkit TabContainer and dynamically setting TabPanel visiblility. When active tab is is hidden (dynamically) the whole Tab Control is hidden, so to avoid this I've written small method like this (setting first visible tab as Active Tab)
private void SetActiveTab()
{
if (tabControl1.Tabs[0].Visible)
{
tabControl1.ActiveTabIndex =0;
return;
}
if (tabControl1.Tabs[1].Visible)
{
tabControl1.ActiveTabIndex = 1;
return;
}
...
}
But this feels like but inefficient/ugly code for me..., Is there a better way of doing this...?
Choose any
for (int tabIndex = 0; tabIndex < TabContainer1.Tabs.Count; tabIndex++)
{
if(TabContainer1.Tabs[tabIndex].Visible)
{
TabContainer1.ActiveTabIndex = tabIndex;
break;
}
}
foreach (TabPanel tab in TabContainer1.Tabs)
{
if (tab.Visible)
{
TabContainer1.ActiveTab = tab;
break;
}
}
var firstVisibleTab = TabContainer1.Tabs.OfType<TabPanel>().FirstOrDefault(tab => tab.Visible);
if (firstVisibleTab != null)
{
TabContainer1.ActiveTab = firstVisibleTab;
}
BTW for such quetions better use Code Review site: Code Review
I have an AutoCompleteExtender from the Ajax Control Toolkit. I need to have a heading in the dropdown list that shows how many items found, but it should not be selectable as an item.
I have tried this using jQuery, but even when I just add as a div, it is still selected as an item into the text box when I click on it:
function clientPopulated(sender, e) {
var completionList = $find("AutoCompleteEx").get_completionList();
var completionListNodes = completionList.childNodes;
for (i = 0; i < completionListNodes.length; i++) {
completionListNodes[i].title = completionListNodes[i]._value.split(':')[2];
}
var resultsHeader;
if(completionListNodes.length==1000)
resultsHeader = 'Max count of 1000 reached.<br/>Please refine your search.';
else if(completionListNodes.length>0)
resultsHeader = completionListNodes.length + ' hits.';
else
resultsHeader = msg_NoObjectsFound ;
jQuery(completionListNodes[0]).before('<div>' + resultsHeader + '</div>');
}
Add OnClientItemSelected and OnClientShowing events handlers and try script below:
function itemSelected(sender, args) {
if (args.get_value() == null) {
sender._element.value = "";
}
}
function clientShowing() {
var extender = $find("AutoCompleteEx");
var optionsCount = extender.get_completionSetCount();
var message = "";
if (optionsCount == 1000) {
message = 'Max count of 1000 reached.<br/>Please refine your search.';
}
else if (optionsCount > 0) {
message = optionsCount + " hits."
}
else {
message = "oops."
}
jQuery(extender.get_completionList()).prepend("<li style='background-color:#ccc !important;'>" + message + "</li>");
}
Added:
you even can do this without OnClientItemSelected handler:
function clientShowing() {
var extender = $find("AutoCompleteEx");
var oldSetText = extender._setText;
extender._setText = function (item) {
if (item.rel == "header") {
extender._element.value = "";
return;
}
oldSetText.call(extender, item);
};
var optionsCount = extender.get_completionSetCount();
var message = "";
if (optionsCount == 1000) {
message = 'Max count of 1000 reached.<br/>Please refine your search.';
}
else if (optionsCount > 0) {
message = optionsCount + " hits."
}
else {
message = "oops."
}
jQuery(extender.get_completionList()).prepend("<li rel='header' style='background-color:#ccc !important;'>" + message + "</li>");
}
We can give a better answer if you post the output html of your autocomplete control. Anyway if its a dropdown control;
jQuery(completionListNodes[0]).before('
<option value="-99" disabled="disabled">your message here</option>'
);
The answer by Yuriy helped me in solving it so I give him credit although his sollution needed some changes to work.
First of all, the clientShowing event (mapped by setting OnClientShowing = "clientShowing" in the AutoExtender control) is executed on initialization. Here we override the _setText method to make sure nothing happens when clicking on the header element. I have used the overriding idea from Yuriy's answer that really did the trick for me. I only changed to check on css class instead of a ref attribute value.
function clientShowing(sender, e) {
var extender = sender;
var oldSetText = extender._setText;
extender._setText = function (item) {
if (jQuery(item).hasClass('listHeader')) {
// Do nothing. The original version sets the item text to the search
// textbox here, but I just want to keep the current search text.
return;
}
// Call the original version of the _setText method
oldSetText.call(extender, item);
};
}
So then we need to add the header element to the top of the list. This has to be done in the clientPopulated event (mapped by setting OnClientPopulated = "clientPopulated" in the AutoExtender control). This event is executed each time the search results have been finished populated, so here we have the correct search count available.
function clientPopulated(sender, e) {
var extender = sender;
var completionList = extender.get_completionList();
var completionListCount = completionList.childNodes.length;
var maxCount = extender.get_completionSetCount();
var resultsHeader;
if(completionListCount == maxCount)
resultsHeader = 'Max count of ' + maxCount + ' reached.<br/>'
+ 'Please refine your search.';
else if(completionListCount > 0)
resultsHeader = completionListCount + ' hits.';
else
resultsHeader = 'No objects found';
jQuery(completionList).prepend(
'<li class="listHeader">' + resultsHeader + '</li>');
}
I have also created a new css class to display this properly. I have used !important to make sure this overrides the mousover style added from the AutoExtender control.
.listHeader
{
background-color : #fafffa !important;
color : #061069 !important;
cursor : default !important;
}
I am using ASP.NET with C# 2.0 and Visual Studio 2005. I am using a Master page and content pages. I have a treeview menu in the master page and when a user selects any menu item I redirect to that content page.
My problem is that after a user navigates to the content page all the treenodes refresh and the structure is collapsed. I want the selected treenode to stay expanded.
Can anybody help me out?
Are you using the treeview inside any UpdatePanel? Actually UpdatePanel does not support TreeView. I however managed the same using a lot of additional codes. You can see most of them on http://www.geekays.net/post/Using-TreeView-inside-AJAX-UpdatePanel.aspx and another post on the same site: http://www.geekays.net/post/TreeView-control-postbacks-on-check-and-uncheck-of-the-nodes-Checkbox.aspx
I added javascripts like the following also to scroll to a tree node that was selected, but the success was poor:
function scrollSelectedTviewNodeToDisplay(){
try{
var inpSelectedNode = document.getElementById("ctl00_contRMSMaster_TViewDeviceHeirarchy_SelectedNode");
var divTree = document.getElementById("ctl00_contRMSMaster_TViewDeviceHeirarchy");
if (inpSelectedNode.value != "")
{
var objScroll = document.getElementById(inpSelectedNode.value);
//my treeview is contained in a scrollable div element
var posY =findPosY(objScroll);
//alert(posY);
if (divTree){
divTree.scrollTop = posY;
//alert(divTree.nodeType);
}
//this works as well bu, but there is not as much control over the y position
//document.all(inpSelectedNode.value).scrollIntoView(true);
}
}
catch(oException)
{
//alert(document.getElementById("ctl00_contRMSMaster_divTree"));
}
}
function findPosX(obj){
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function findPosY(obj){
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}