I would Like to parse the Metadata to a Book. Whild trying to retrieve the Booktitle, I noticed I can't access the ChildNodes from an Element that contains a TextNode. Here is my Data:
<div id="detail_content_wrapper">
<h1>
MyBookTitle 22<br>
<span class="sub">
subtext
Book 22
by Foo Bar
</span>
</h1>
I retrieve the Elements within "detail_content_wrapper" using:
Document parsedObject = Jsoup.parse(source);
Element bookNotes = parsedObject.getElementById("detail_content_wrapper");
Element h1Element = bookNotes.getElementsByTag("h1").first()
This will give me the complete content inside the h1-Tag.
When I take a look at the h1-Element ChildNodes, the first Childnode is a TextNode that holds the BookName. BUT when I try to get the Content of the First Child...
Element bookName = h1Element.children().first();
OR Element bookName = h1Element.childNode(0);
...This will, in both cases, contain the 2nd node which is the br-Element.
Is this a bug or am I using Jsoup wrong?
Related
I have the following DOM:
<p>
<strong>Success!<strong>
"1 item(s) added to cart!"
</p>
How can I get the text "Success!1 item(s) added to cart!"?
I want to verify that this element is visible on the page and contains this text.
I tried to use this as a locator:
this.successMessage = page.locator('text=Success!1 item(s) added to cart!');
but when I do:
public async getSuccessMessageText(): Promise<string | null> {
return await this.successMessage.textContent();
}
And:
const successMessageText = categoryPage.getSuccessMessageText();
expect(successMessageText).toBe(messagesData.successAddToCartMessage);
The test breaks with:
Error: expect(received).toBe(expected) // Object.is equality
Expected: "Success!1 item(s) added to cart!"
Received: {}
Is it possible that the <strong> tag is making troubles for the textContent() function? How to retrieve this text otherwise?
Can you please help?
Hi here the scenario i created a SITE1 where in the blog it has an examine search engine and it is working correctly. now I have to copy my whole page to duplicate it for my new demo SITE2 then I test my search engine and it picked the searched item on the page it self "AND IT ALSO PICKED THE ITEM ON THE SITE1!" :/ that's bad issue..
Any idea how to avoid to picked search item on the other site or content??
Here is my search code:
#{
string searchTerm = Request.QueryString["search"];
var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.And);
var query = searchCriteria.GroupedOr(new string[] { "nodeName", "addblogImage", "blogTitle", "datePublished", "blogCategory", "blogAuthor", "blogbodyText", "blogreadMore" }, searchTerm).Compile();
var searchResults = searcher.Search(query);
}
#{
try {
if (searchResults.Any()){
<div class="items-row cols-3 row-0 row-fluid clearfix clean-list background-white">
<div class="span4 post padding">
#foreach (var result in searchResults){
var node = Umbraco.Content(result.Fields["id"]);
<div class="item column-1" itemprop="blogPost" style="margin:0">
#if(node.HasValue("addblogImage")){
var blogImg = Umbraco.TypedMedia(node.GetPropertyValue<string>("addblogImage"));
<img src="#blogImg.Url" alt="" width="898" height="597">
}
Sounds like both sites use the same search index.
Make sure in ExamineIndex.config the indexers are using a different IndexPath
For more useful Examine documentation, check out: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine
I am trying to select a paper-tab based on it's data-id attribute. I have the element but I cannot changed to selected property of the inner_tabview.
I have a Polymer:
<paper-tabs id="inner_tabview" noink="true">
<template repeat="{{item in tabNames}}">
<paper-tab data-id="{{item['id']}}"><h3>{{item['name']}}</h3></paper-tab>
</template>
</paper-tabs>
And some Dart code behind it:
selectTab(itemId) {
PaperTab item = shadowRoot.querySelector("paper-tab[data-id='" + itemId + "']");
print('Selecting: ' + itemId + ', text:' + item.text);
PaperTabs tabView = shadowRoot.querySelector('#inner_tabview');
tabView.selected = item; // This doesn't work
}
Changing the selected using an integer (index) works, but I don't know what the index should be.
Only thing I can currently think of is finding all paper-tab elements and get the index of the correct element in that List. But that sounds a bit silly to do so.
Any other way?
I don't know why querySelector doesn't work but selected expects an index by default not an element.
if you specify the valueattr attribute you can use other attributes than the index.
<paper-tabs id="inner_tabview" noink="true" valueattr="data-id">
<template repeat="{{item in tabNames}}">
<paper-tab data-id="{{item['id']}}"><h3>{{item['name']}}</h3></paper-tab>
</template>
</paper-tabs>
then
tabView.selected = itemId;
should work as well
I'm currently finishing a feature with list reordering and I'm stuck with a probably very simple thing, but I'm really sorry that I can't figure out how to solve it .... ( possibly my brain just ignores this logic :) )
The purpose is simple :
I have a list of items with a "position" data (different from $index).
I drag and drop items to change their order.
When the drag stops, all items in the list should have a new position, that'll be updated with a $resource object.
For example, after dragging I have this:
$index elem.position
0 2
1 1
2 3
should automatically change position 2->1, 1->2 and 3->3.
The problem :
With angularUI I can have the current item index but not the others in the list. So I can't change the whole list index after stopping the drag. And it's frustrating because on view, I can catch easily $index but not in controller.
Code :
in controller.js
$scope.updateSortable = {
stop: function(e, ui) {
for (var i=0; i<$scope.list.length; i++) {
var elem = $scope.list[i];
// here's don't know how to update elem.position
//elem.position = ui.item.index; // bad one, I know :)
//elem.$update();
}
},
placeholder: "xp-hightlight",
axis: 'y'
};
in html page :
<div ng-repeat="el in list">
<div>
<span class="position" ng-bind="el.position"></span>
</div>
</div>
The json items look like that :
{ id: 47, description: "my text in the list", position: 1}
Would this work for you, or do you have to have the position variable set?
<div ng-repeat="el in list">
<div>
<span class="position">{{$index + 1}}</span>
</div>
</div>
I added this to your controller 'testCtrl'. You can update the position element within the callback of this watch:
var _list;
$scope.$watch(function() {
return JSON.stringify($scope.items)
},function(_l) {
if(typeof _l !== 'undefined') {
_list = JSON.parse(_l);
console.log(_list)
}
});
I just solved the issue, and thanks to koolunix I managed the update of position directly inside the controller with this plunkr :
http://plnkr.co/edit/kDkNLSjoHbnaumk2uaOF?p=preview
The main fact was just to manage the position with the loop in list items.
elem.position=i+1;
I'm having trouble converting text to a hyperlink in a controller, then sending it to the view.
So far, I have:
Controller:
foreach (dynamic tweet in Timeline())
{
string text = tweet["text"].ToString();
const string pattern = #"http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\#\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?";
Regex regexCheck = new Regex(pattern);
MatchCollection matches = regexCheck.Matches(text);
for (int i = 0; i < matches.Count; i++)
{
text = string.Format(#"<a href={0}>{1}</a>", matches[i].Value, matches[i].Value);
}
timeline.Add(text);
}
View:
#Html.DisplayFor(model => model.Timeline)
But It keeps displaying the literal text!
Display: <a href=http://t.co/fm0ruxjVXe>http://t.co/fm0ruxjVXe</a>
Could anyone please show me how this is done? I am quite new to MVC.
since you are sending out html already, try
#Html.Raw(Model.Timeline)
Another option is to send out just the url and the text and build the a tag in the view
#Model.Timeline.Text
That will involve changing your timeline property to being an object with two properties, text and url .
The #Html.DisplayFor helpers in Razor automatically encode the output
If you want to just output the content of model.Timeline, try just using Response.Write