Output contents of label array in Blogger expression - arrays

I'm attempting to generate the labels of a blog post within the post container as classes, like so:
<div expr:class='"post hentry grid-item" + (data:post.labels any (l => l.name !="" : " " + l.name)' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'>
Help would be greatly appreciated!

As Lambda expressions in Blogger generate arrays(in some cases boolean and numbers as well) as their results, we need some way to iterate over that array. We can use a b:loop tag for that. Also, as we can't include a b:loop tag in class attribute (otherwise the Blogger's XML parser will show errors) therefore escaping the HTML and including the b:loop tag is one of the way. The code will look like -
<div class='post hentry grid-item <b:loop var="labelName" values="data:post.labels" ><b:eval expr='data:labelName.name + " " ' /></b:loop>' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'>
</div>

Related

React module.css add part of class name dynamically

I would like to add a part of a classname dynamicall with modules.css.
My classnames are arrow1, arrow2, arrow3, arrow4. So I would like to change the number at the end dynamically.
className={`${styles.box}` + ' styles.arrow' + id}
I tried it liek this and some other ways, but it never worked. How can I add the number (id)?
You're currently adding a string "styles.arrow1" which does not reference the styles object. Instead you can target your className like so
className={`${styles.box} ` + styles["arrow" + id]}

Testing-library: not picking up the match by text

No matter what I use .getByText(), or .toHaveTextContent() I am unable to select the text inside my Dom element which looks like this :
<h4 data-testid={playerName + "_score"}>Total Score- {score || 0}</h4>
Here I am trying to run the test By ID :
expect(screen.getByTestId("Vaibhav_score")).toHaveTextContent('Total Score- 0')
Not when I see the browser, I see it in two lines like :
Total Score-
0
and similary in the testing console :
<div>
<h4 data-testid="Vaibhav_score" >
Total Score-
0
</h4>
</div>
can someone help me in identifying the issue?
That's probably because of the way the text is been rendered against the string. why no you better try with something like:
expect(screen.getByTestId("Vaibhav_score")).toHaveTextContent(/^Total Score- 0/)
Also, retrieving by test Id is shouldn't be your first option. Maybe a better way to test it could be:
expect(screen.getByText(/^Total Score-/)).toHaveTextContent(/^Total Score- 0/)
let me know if it helps

How to extract dynamic number in header tag in selenium?

here is the html. I want to extract 1814400752 in h2 tag.
I have tried using xpath but it extracts just "Order number:" without number. Please advise.
<h2 _ngcontent-c57="">
<pwwgen-label _ngcontent-c57="" default="Order number:" name="e-comm-confirmation-order-number" _nghost-c8="" ng-reflect-name="e-comm-confirmation-order-numb" ng-reflect-default="Order number:">
<span _ngcontent-c8="">Order number:
</span>
</pwwgen-label>
1814400752</h2>
You have to select the parent tag from the child xpath
Below XPath can be used
Xpath: //*[name='e-comm-confirmation-order-number']/parent::h2
driver.findElement(By.xpath("//*[name='e-comm-confirmation-order-number']/parent::h2")).getText();
As per the HTML you have shared the text 1814400752 is a child node of <h2> tag. To extract the text 1814400752 you can use the following solution (Java):
WebElement myElement = driver.findElement(By.XPath("//h2[#_ngcontent-c57]"));
String myText = ((JavaScriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", myElement).toString();
It was taking time to render the number on the page, so it could not extract it immediately after executing below code. I have to use some sync and then execute and it worked. Thanks for all your responses.
WebElement myElement = driver.findElement(By.XPath("//h2[#_ngcontent-c57]"));
String output = element.getAttribute("innerText");

Is there any way to include OR/AND inside a CSS selector for web scraping

What I am trying to do, is to scrape from a website that has changed its structure through time, obtaining a <p> child from all H2 OR H3 that .contains(RESEARCHER).
Currently I can do that separately with H2 or H3, but it seems to be creating some errors when I export to .csv. This is what I am doing:
'Researcher': response.css(".field-item.even h2:contains(RESEARCHER) + p ::text").extract(),
'Researcher': response.css(".field-item.even h3:contains(RESEARCHER) + p ::text").extract(),
Is there a way to combine them in a single expression?
No, the best you can do is put both selectors in the same string with a comma in between:
response.css(".field-item.even h2:contains(RESEARCHER) + p ::text, .field-item.even h3:contains(RESEARCHER) + p ::text").extract()

Write scope within dynamic string

I am working on localization within my angular project. It reads a JSON file which is having key and it's localized value in string.
Like: text1:"Localized text"
This prints "Localized text" on page correctly. But when I need to add some dynamic text in the string, like:
text1: "Showing page {{cur_page_num}} of {{total_pages}} pages"
where the cur_page_num and total_pages values will come from controller. I have tried
"Showing page {{cur_page_num}} of {{total_pages}} pages"
but it's printing {{cur_page_num}} and {{total_pages}} as it is without evaluating it.
use ng-bind-html
EX:
<p ng-bind-html="obj.text1"></p>
At this point you may get an error.
attempting to use an unsafe value in a safe context error
you need to either use ngSanitize or $sce to resolve that.
try storing the json values in an array .
iterate it on html & render it there .
if it is from template then your code should be like this,
text1: "Showing page " + {{cur_page_num}} + " of " + {{total_pages}} + " pages"
or if it is from controller then it can be like below,
text1: "Showing page " + $scope.cur_page_num + " of " + $scope.total_pages + " pages"

Resources