Selenium get all child nodes - c#

You guys, I have a HTML like this:
<li class="selectBox-selected selectBox-hover">
<a rel="0">Select payee type</a>
</li>
<li class="">
<a rel="1">Injured Worker</a>
</li>
<li class="">
<a rel="2">Employer</a>
</li>
<li class="">
<a rel="4">Creditor</a>
</li>
This is code to get all the above option into the list:
List<IWebElement> lstOption = ConstantsLib.driver.FindElements(By.XPath("//li[. = 'selectBox-selected selectBox-hover']/following-sibling::li")).ToList();
Actually It does not work. I dont know if Where I am wrong.
Please help me. Many thanks.

Try changing your XPath to:
//li[contains(#class, 'selectBox-selected selectBox-hover')]/following-sibling::li

Related

Razor Page, How to routing with tag helper asp.net core

I don't know how to get this string ?CurrentPage=2
this is my code
#page "/Category/{IdCategory}"
#using RN.Sieuthibamien.com.Data.Models
#model RN.Sieuthibamien.com.Pages.IndexModel
#{
ViewData["Title"] = "Category";
var id = Model.IdCategory;
}
<div>
<ul class="pagination">
<li class="page-item #(!Model.ShowFirst ? "disabled" : "")">
<a asp-page="./Category/#Model.IdCategory" asp-route-CurrentPage="1" class="page-link"><i class="fa fa-fast-backward"></i></a>
</li>
<li class="page-item #(!Model.ShowPrevious ? "disabled":"")">
<a asp-page="./Category/#Model.IdCategory" asp-route-CurrentPage="#(Model.CurrentPage -1)" class="page-link"><i class="fa fa-step-backward"></i></a>
</li>
<li class="page-item #(!Model.ShowNext ? "disabled":"")">
<a asp-page="./Category/#Model.IdCategory" asp-route-CurrentPage="#(Model.CurrentPage + 1)" class="page-link"><i class="fa fa-step-forward"></i></a>
</li>
<li class="page-item #(!Model.ShowLast ? "disabled":"")">
<a asp-page="./Category/#Model.IdCategory" asp-route-CurrentPage="#Model.TotalPages" class="page-link"><i class="fa fa-fast-forward"></i></a>
</li>
</ul>
</div>
when I click on next link then route that I want is ./Category/{IdCategory}?CurrentPage=2, but not and result is ./Category/{IdCategory}, Sorry with my English, Please help me
Change your tag helper to this:
<a asp-page="./Category" asp-route-IdCategory="#Model.IdCategory" asp-route-CurrentPage="1" class="page-link"><i class="fa fa-fast-backward"></i></a>
If you are on the same page you should change this from a asp-
page="./Category/#Model.IdCategory" to
<a asp-page="./Category"
and in order to navigate to your data based on what you click, just passed the currentpage to your OnGetAsync
OnGetAsync(int Currentpage){
CurrentPage = Currentpage == 0 ? 1 : Currentpage;
/// rest of the code here
}

ActionLink using Bootstrap 3 submenu not working, url not being called

bootstrap in C# submenus not being called, the url is shown in the bottom of the browser but when clicked nothing happens. What I am doing wrong?
<div class="navbar-collapse collapse dropdown">
<ul class="nav navbar-nav" role="menu">
<li role="menuitem">#Html.ActionLink("Contracts", "Index", "Contracts")</li>
<li class="dropdown-submenu" data-toggle="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Configuration <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li role="menuitem">#Html.ActionLink("Contract Type", "ContractType",
"Configuration")</li>
<li role="menuitem">#Html.ActionLink("Cost Type", "CostType",
"Configuration")</li>
</ul>
</li>
</ul>
</div>
check your ActionResult does it match with your .chtml page ActionLink
I upgraded to Bootstrap 4.1. Now it is OK
<ul class="navbar-nav mr-auto">
<li class="nav-item #Html.IfSelected("Proposals")">
<a class="nav-link" href="#Url.Action("Index", "Proposal")">Proposals</a>
</li>
<li class="nav-item #Html.IfSelected("Contracts")">
<a class="nav-link" href="#Url.Action("Index", "Contracts")">Contracts</a>
</li>
<li class="nav-item #Html.IfSelected("Reporting")">
<a class="nav-link" href="#Url.Action("Reporting", "Home")">Reporting</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Configuration
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#Url.Action("Actions", "Configuration")">Actions</a>
<a class="dropdown-item" href="#Url.Action("ContractType", "Configuration")">Contract Type</a>
<a class="dropdown-item" href="#Url.Action("CostType", "Configuration")">Cost Type</a>
<a class="dropdown-item" href="#Url.Action("PendingOn", "Configuration")">Pending On</a>
<a class="dropdown-item" href="#Url.Action("Periods", "Configuration")">Periods</a>
<a class="dropdown-item" href="#Url.Action("Operators", "Configuration")">Operators</a>
<a class="dropdown-item" href="#Url.Action("SellerType", "Configuration")">Entity Type</a>
<a class="dropdown-item" href="#Url.Action("Status", "Configuration")">Status</a>
<a class="dropdown-item" href="#Url.Action("Result", "Configuration")">Results</a>
<a class="dropdown-item" href="#Url.Action("Vendors", "Configuration")">Vendors</a>
<a class="dropdown-item" href="#Url.Action("Users", "Configuration")">Users</a>
</div>
</li>
</ul>

How to get a specific a tag?

I'm using HtmlAgilityPack and I'm trying to get a specific a tag which contains a particular text inside.
Suppose that I have this html structure:
<ul>
<li class="current">
Summary
</li>
<li class="">
H2H Comparison
</li>
<li class="">
Commentary
</li>
<li class="">Venue
</li>
<li class="">
Map
</li>
</ul>
I want get the a tag that contains as InnerText: "Venue".
Actually my idea is this:
var nodes = nodes.SelectNodes("//li//a");
HtmlNode a;
foreach(var node in nodes)
{
if(node.InnerText.ToLower().Contains("venue"))
{
a = node;
break;
}
}
this is code working but exist another way maybe using xpath or something like?
This will return all anchor tags that contain the word "Venue" //a[contains(text(),'Venue')]

Displaying dropdown of links with query builder

I am trying to create a dropdown in Umbraco 7, using the query builder. The dropdown is part of a navbar, which contains links to other pages as well. The page contains HTML with Razor code.
#{
var selection = Model.Content.Site().FirstChild("Sprog").Children()
.Where(x => x.IsVisible());
}
<ul class="sf-menu well" data-type="navbar">
#foreach(var item in selection){
if(item.Name == "Sommerhuse") {
<li>
Sommerhuse
#{
var selection2 = Umbraco.TypedContent(1090).Children()
.Where(x => x.IsVisible());
}
<ul>
#foreach(var sommerhus in selection2){
<li>
#sommerhus.Name
</li>
}
</ul>
</li>
} else {
<li>
#item.Name
</li>
}
}
</ul>
I tried nesting another query builder with the content I need for the dropdown into my navbar query builder and iterating through that
But this still doesn't create the dropdown. Instead it just returns a static link, where the dropdown should be shown. In my HTML prototype, the dropdown works fine using this code.
<nav class="nav pull-right">
<ul class="sf-menu well" data-type="navbar">
<li class="active">
Forside
</li>
<li>
Lejebetingelser
</li>
<li>
Sommerhuse
<ul>
<li>
Blokhus
</li>
<li>
Hvide Sande
</li>
<li>
Langeland
</li>
<li>
Marielyst
</li>
<li>
Ebeltoft
</li>
<li>
Rørvig
</li>
<li>
Bogense
</li>
</ul>
</li>
<li class="">
Kontakt
</li>
<li>
</li>
</ul>
</nav>
Apologies for the bad formatting, for some reason Visual Studio refuses to auto-format .cshtml files.
You don't have the <nav class="nav pull-right"> in your razor script.
Tip: do not compare on the name of a page because this will break your dropdown if the content editor changes the node name.
if(item.Name == "Sommerhuse") { // BAD IDEA
rather use the documentTypeAlias (if it is another document type)
if(item.DocumentTypeAlias == "aliasOfTheDocumentType") { // much safer
That will only work if the page has a special document type of course.

setting active class in c#.net masterpage

<div id="navigation">
<ul class="nav nav-pills">
<li role="presentation">Home</li>
<li role="presentation">Open Account</li>
<li role="presentation">ATM</li>
<li role="presentation">Branch Locator</li>
<li role="presentation">Contact US</li>
</ul>
</div>
I want to set active class in li tag based on the visited link, I have tried several answers from Stackoverflow but none seems to me working.
For your information, I am using Bootstrap, C#, Visual Studio for my development.
Your elements should look like (in master.page):
<li role="presentation" id="liDefault" runat="server">Home</li>
public String linkDefault
{
get
{
return "not_active";
}
set
{
liDefault.Attributes.Add("class", "" + value + "");
}
}
Then add following to your head part of content page:
<%# MasterType VirtualPath="~/MasterPage.master" %>
And code behind of your content page:
this.Master.linkDefault = "active";
You can achieve it using Jquery.
First set single class on all anchor tags in you li tags i.e:
<div id="navigation">
<ul class="nav nav-pills">
<li role="presentation">Home</li>
<li role="presentation">Open Account</li>
<li role="presentation">ATM</li>
<li role="presentation">Branch Locator</li>
<li role="presentation">Contact US</li>
</ul>
</div>
Now in jquery you have to check if any anchor tag is clicked so an "active" class will be set to its parent li tag. i.e.:
$(".link").click(function(){
$(this).parent().addClass("active");
})
Hope its works.

Categories

Resources