I have html code, which looks like that:
<p>Some text</p>
<p>Some text</p>
<h2>title</h2>
<ul>
<li> element </li>
<li> element </li>
<li> element </li>
...
</ul>
<h2>title 2</h2>
<ul>
<li> element </li>
<li> element </li>
<li> element </li>
...
</ul>
etc.
My question is: how can i get all < li> elements into a List? I don't need titles, i just want elements from lists.
I think HTML Agility Pack could be a solution, but i have no idea how to do that. Thanks for help!
Related
I have a ASP-WebForm-Application with several User-Rights.
In CodeBehind I am hiding some Elements if the specific Rights aren't given. But with F12 the User could manipulate the Code the get some Functionallity he isn't allowed to.
Are there any possibilities to hide Elements from CodeBehind, that they aren't make visible via Code-Manipulation? Something like destroying them completely in CodeBehind?
For example a Navigation based an List-Element, where I want to hide some Links:
<ul>
<li>
<a>link 1<a/>
</li>
<li>
<a>link 2<a/>
</li>
<li>
<a>link 3<a/> // Has to be hidden by some conditions
</li>
</ul>
Hope someone could help me!
You can use the asp:PlaceHolder or the asp:Panel and warp your content and make it visible or not.
Alternative you can add on the element the runat="server" Visible="false" and manipulate the visible.
Examples:
<ul>
<li>
<a>link 1<a/>
</li>
<li>
<a>link 2<a/>
</li>
<li runat="server" id="pnlToHide">
<a>link 3<a/> // Has to be hidden by some conditions
</li>
</ul>
or
<ul>
<li>
<a>link 1<a/>
</li>
<li>
<a>link 2<a/>
</li>
<asp:PlaceHolder runat="server" ID="pnlToHide2">
<li>
<a>link 3<a/> // Has to be hidden by some conditions
</li>
</asp:PlaceHolder>
</ul>
and on code behind
pnlToHide.Visible = false;
I need to click on tab "Pis/Cofins" in my application
<ul class="nav nav-tabs" id="tabs">
<li class="">
Dados Gerais
</li>
<li class="active">
Pis/Cofins
</li>
<li>
Combustíveis
</li>
<li>
Modo de Servir
</li>
<li>
Imagens
</li>
<li>
Informações
</li>
</ul>
You may simply use the following xpath:
//a[text()='Pis/Cofins']
You may use extension like Firebug in firefox to easily find locators and use them in your test scripts
As per the HTML you have shared to click on tab with text as Pis/Cofins you can use either of the following solutions:
LinkText:
driver.FindElement(By.LinkText("Pis/Cofins")).Click();
CssSelector:
driver.FindElement(By.CssSelector("ul.nav.nav-tabs#tabs a[href$='pisCofins']")).Click();
XPath:
driver.FindElement(By.XPath("//a[contains(#href,'pisCofins') and contains(.,'Pis/Cofins')]")).Click();
Is it possible to put Text in a element outside the <form runat="server"> tag?
I'm trying to at least output my Session values like the user's name in a <a> element.
In my login.aspx.cs i start the session
Session["username"] = firstname.Text;
and then try to output it on other pages navigation that is outside the <form> tag
<div class="collapse navbar-collapse" id="navbar-brand-centered">
<ul class="nav navbar-nav">
<li>Home</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><!--The place where i will output--></li>
<li>Logout</li>
</ul>
</div>
i tried to call the id of the <a> it doesn't appear in suggestion and i started to think that its outside the server tag.
Thank you for understanding and for helping.
Use it like <%# Session["username"].ToString() %>, you need not set from code behind, you will directly access to it.
<div class="collapse navbar-collapse" id="navbar-brand-centered">
<ul class="nav navbar-nav">
<li>Home</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><%# Session["username"].ToString() %></li>
<li>Logout</li>
</ul>
</div>
Didn't work dropdownlist Risk Content in master page after change page to the setting page. The dropdown just work after go back to home page again
MasterPage.master
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav custom_nav">
<li class="">Home
</li>
<li class="dropdown">Risk Context
<ul class="dropdown-menu" role="menu">
<li>Objective (KPI)
</li>
<li>Risk Limit & Expected Residual Risk
</li>
<li>Impact Scale Tables
</li>
<li>Probability Scale Tables
</li>
</ul>
</li>
<li>Settings
</li>
<ul>
</div>
What I miss from my code?? help me. thank before..
I don't know how to apply CSS for a HTML generic control like <UL> and <LI> given runat="server" in ASP.NET. I am finding the <li> in a master page from a content page. Once I found that control I want to apply CSS.
<ul id="mainMenu" runat="server" style="width:350px;">
<li id="mainHome" runat="server"><a title="Home" href="#" class="home">Home</a></li>
<li id="mainManage" runat="server"><a title="Manage" href="#"
class="manage">Manage</a></li>
<li id="mainEnquiry" runat="server"><a title="Enquiry" href="#"
class="enquiry">Enquiry</a></li>
<li id="mainReport" runat="server"><a title="Report" href="#"
class="report">Reports</a></li>
</ul>
Please try this,
ull.Style.Add("background-color", "Red");
Or, I have tested this, will definitely work, please check
ull.Attributes.Add("class", "yourClass");
Edit:
To test this solution I have provided you:
make new blank master page and put <ul runat="server" id="ull">
then add a new page and use the above master page.
make findcontrol ul and put in CSS as I have mentioned in the answer.
then run your page, and view source of your HTML page and you will find what you are looking for. Like