Html.ActionLink syntax error - actionlink

I want to change this
<a class="more" href="Subject?SubjectId=#Html.DisplayFor(model => item.Id)">Devamı »</a>
to
<a class="more"#Html.ActionLink("Devamı ", "Subject", new {Subject?SubjectId= item.Id }) ></a>
I can not put &raquo and Subject?SubjectId= to #Html.actionlink.
Why?

If you take a look at Microsoft's site, it says Html.ActionLink returns a complete anchor (<a></a>) object based on the parameters you give it.
You can't put the anchor returned by ActionLink into your anchor element. Choose one of the other ways of creating the link.
You may be looking for the Url.Action method, http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.action(v=vs.108).aspx
<a class="more" href=#Url.Action("ControllerName", new {SubjectId = item.Id})
>Devamı »
</a>

Related

Get ChildElement without using element selector

I am using a protractor to get the text in the second Div within #myDiv. Can someone please advise how can I get a text from the second Div (complete Text) which is 'This is a sample text'. I tried getting text in #myDiv but it adds spaces before the phrase. I want to exactly get the text from the 2nd child element of the after #myDiv.
<div id='myDiv'>
<span> (this is second div)
<a name="aTag"></a>
<madcap:concept term="DoSomething">
This
<span class="myClass">
is a
</span>
sample text
</madcap:concept></h1>
</span>
</div>
please try with following-sibling xpath as below :
element(by.xpath("//*[following-sibling::div[#id='myDiv']]"))
Hope this works!
let text = await element(by.xpath('//div[#id="myDiv"]//span[1]')).getText();
console.log(text) 
worked fine for me
I added your html in component html and checked it.

How to use onclick method inside AEM component

Am having a AEM6 html component, am getting the values from dialog and using it inside the component via the .js file and using the return properties.
I could able to get the authored values but it is getting null or empty when am using it inside the onclick method. Please find below the code snippet below.
<div data-sly-unwrap data-sly-use.test="test.js"></div>
<a href="#" class="${test.testId}" id="${test.testId}" onClick="toggleDraw('${test.testId}')" >
The content I authored is getting displayed in class and Id, but it is not displaying in the onClick method.
Below is the Output am getting after authoring.
<a href="#" class="get-a-quote" id="get-a-quote" onClick="toggleDraw('')" >
Output I needed is :
<a href="#" class="get-a-quote" id="get-a-quote" onClick="toggleDraw('get-a-quote')" >
This should do the trick:
<a data-sly-test.variable123="toggleDraw('${test.testId}')" href="#" class="${test.testId}" id="${test.testId}" onclick="${variable123 # context='attribute'}" >
You need to put the function call in a variable because of the nested single quotes. And you need to manually set the context in this case. If "attribute" does some escaping you do not like, you could use "unsafe" - this will end in all escaping mechanisms being disabled. That might or might not be a security issue for your application.
HTH

Get inner most regex match for a href regex catcher

I want to catch href tags with a youtube link inside them.
I have this regex:
"<a.*?href=(.*?youtu.?be.*?)>.*?</a>"
It works but it doesn't stop if the tag is closed.
Meaning if I have:
<a href=www.google.come>google</a> <a href=www.youtube.com>youtube</a>
Desired result:
<a href=www.youtube.com>youtube</a
Actual result:
<a href=www.google.come>google</a> <a href=www.youtube.com>youtube</a>
It catches the whole thing, recognizing Googles <a as the opener and youtubes </a> as the closer.
I want to make my regex a little smarter so it knows how to stop the match when the the Google closer appeared, and start a new match attempt when the Youtube opener appears.
I tried this but it didn't work:
"<a.*?[^>]href=(.*?youtu.?be.*?)>.*?</a>"
And also tried this:
"<a[^>].*?href=(.*?youtu.?be.*?)>.*?</a>"
You can try this pattern :
"<a[^>]*?href=[^>]*?youtu.?be[^>]*?>[^>]*?<\/a>"

Find an Element in Protractor

<div>
<label localize="{data: 'Name', suffix: ':'}">Name:</label>
<span class="required" ng-class="{'disabled': meterCreating}" input-control="{title: 'Meter', okCallback:setMeterName, value: meter.meterName, ss: 'meters'}">
<span hs-placeholder="Enter Name" class="ng-binding"></span>
</span>
</div>
What is the best way to find an element: placeholder = "Enter Name"?
Scenario: find an element using Snippet above
User clicks on the "Enter Name" box, another windows pops-up for entering a name.
Based off that HTML, the cleanest way I can see is by css chaining:
element(by.css('span.required span.ng-binding')) (would normally just be span.ng-binding, but I highly doubt that's unique. I also doubt that span.required span.ng-binding is unique either)
There are many other options, however they won't be pretty cause they will be similar chains.
element(by.cssContainingText('label', 'Name:')).element(by.css('span > span'));
or
element(by.css('div label span.ng-binding')) etc..
I would suggest asking your developers for better locators (specifically, ID's), it makes JavaScript way easier. Unfortunately, I don't think you're able to locate that element by HTML attributes, which is one of my favorite ways. It would have looked like this:
element(by.css('span[placeholder=Enter Name]')) -- but I'm pretty sure that will throw an error for invalid locator. It accepts most "standard" html attributes such as value, option, style etc...

Updating an existing HTML link using GWT?

HTML file:
<a id="search">Search</a>
GWT Module:
Anchor searchLink = new Anchor("Search", Window.Location.createUrlBuilder().setPath("search.html").buildString());
RootPanel.get("search").add(searchLink);
Results in:
<a id="search">Search
<a class="gwt-Anchor" href="http://127.0.0.1:8888/search.html?gwt.codesvr=127.0.0.1:9997">Search</a>
</a>
Is there a way for me to edit the existing anchor (replacing its body) instead of inserting inside it?
Use Document#getElementById() to get the existing anchor Element instead of RootPanel#get():
Anchor searchLink = Anchor.wrap(Document.get().getElementById("search"));
searchLink.setHref(Window.Location.createUrlBuilder().
setPath("search.html").buildString());
The correct use of GWT Document class is:
Document.get().getElementById("search")