Validating text after <br> in Atata - atata

I have this table cell on my page:
<td>
<strong>Some Text</strong>
<br>random description
</td>
I'd like to come up with a way to validate the text after the br and have it return that as Text<T> so I can use the atata asserts (like Should.Equal("random description")) - separately from the text inside the <strong> but so far have been unable to do anything more than get that text as a string by getting the td via xpath and .Split("\r\n") it's Value - is there a way to get just this text?

You can do that by adding [ContentSource(ContentSource.LastChildTextNode)] attribute to your text control.
Alternatively, you can invoke TextControl.GetContent(ContentSource.LastChildTextNode) method.

Related

Xpath or CSS Selector to select all child nodes that come before a specific child node

I have this following html data :
<span id="description">
<p>description</p>
<p>description</p>
<p></p>
<h3>title1</h3>
some text. <br>
<br>
some text.
<h3>title2</h3>
<p></p>
<p></p>
<div>data</div>
<h3>title3</h3>
<strong>data</strong>
<br>
some text.
<br>
<br>
some text.
<p></p>
</span>
I need to get all the p tags up to first h3 tag.
I tried Xpath //span[#id="description"] which will get all the children of the span tag, which I dont need.
I also tried //span[#id="description"]/h3[1]/preceding-sibling::p which only returned first preceding p tag. Also selecting individual p nodes and then combining them are not feasible since different pages will have different number of p nodes before the first h3.
Then I tried with CSS selectors and remove function, $('#description').clone().children('div,h3').remove().end().html().trim(). Which didnt work well, since I cant select text nodes with it.
Is there anyway I can split the data with these h3 tags?
Your expression
//span[#id="description"]/h3[1]/preceding-sibling::p
should work.
A similar expression
//span[#id="description"]/h3[1]//preceding-sibling::p
should also work.
Also try this one:
//span[#id="description"]/p[following-sibling::h3[contains(text(),"title1")]]

How to format Power Automate's "Create HTML table" to display hyperlink in email pointing to SharePoint

With a SharePoint List as a data source, I have a Power Automate workflow that groups by a field, then emails unique people a list of stuff that's applicable to them. In the email, there should be hyperlinks pointing to editable SP List items. I have the flow working except the hyperlinks in email are not working as expected. Here is the
body of email instead of the expected body of email with hyperlinks. I used "concat('Link')" as a value in "Create HTML table" step and "replace(replace(replace(body('Create_HTML_table'), '<a href="', ''), '<a/>', '')" in "Send an Email" step per this article: . Here is an illustration of the issue.
Firstly, in the list of available fields, use 'Link to item' rather than 'Title' for your link, whether the Title links or not.
Secondly; you can just type the special characters (like the HTML tag greater than ">") normally in the replace, like I have below. However I believe that the two solutions I've given you will perhaps provide a more slick email.
Logic Solution
Rather than relying on nested replace functions, you can parse the created html and make an cleaner result.
Still create the HTML table, but in the item value, put link then insert the SharePoint ID from the dynamic content. If you run this, as an example, the result for the 10th ever item in the list will format like this:
link10
Now run a Apply to each on the Get items action you made the table from, and for each item, you will replace the link# with the required url from the Link to item field in an html link wrapped around the title.
Insert that amended code into the email.
For the flow I have gone as verbose as I can to ensure the logic is obvious, it stands to reason that much of this might be minimised (image after description):
Get items - SharePoint pull, no filter, only 3 items (car, boat, plane).
Create HTML table - Details:
'From' - The "value" dynamic content from 'Get items'.
#{outputs('Get_items')?['body/value']}
'Columns' - "Custom" with one entry:
'Header' - "item"
'Value' - "link#{item()?['ID']}"
Variables - Initialise these variables:
linkVAR - Initialize an empty string variable.
htmlTabStVAR - Initialize an empty string variable.
findVAR - Initialize an empty string variable.
linkVAR - Initialize a string variable with the output of the 'Create HTML table' action.
Apply to each - 'Select an output from previous steps' must be the same as the table in #2.
Set htmlTabStVAR - This should be the output of the Set htmlTabEnVAR
#{variables('htmlTabEnVAR')}
Set findVAR - This sets the variable the replace function will use to find the right item:
link#{items('Apply_to_each')?['ID']}
Set linkVAR - This sets the desired HTML for the link:
#{items('Apply_to_each')?['Title']}
Set htmlTabStVAR - This should be the output of the Set htmlTabEnVAR
replace(variables('htmlTabStVAR'), variables('findVAR'), variables('linkVAR'))
Setup your email, here is the body that I used:
<p>this works</p>
<p>table:</p>
#{variables('htmlTabEnVAR')}
Here's the flow image:
Here's the email, and the resultant HTML (from the flow history):
<p>this works</p>
<p>table:</p>
<table>
<thead>
<tr>
<th>item</th>
</tr>
</thead>
<tbody>
<tr>
<td>
car
</td>
</tr>
<tr>
<td>
boat
</td>
</tr>
<tr>
<td>
plane
</td>
</tr>
</tbody>
</table>
To minimise the Apply to each you can remove the link and find variables and use this, longer, replace function in the expression for the htmlTabEnVAR:
replace(variables('htmlTabStVAR'), concat('link', items('Apply_to_each')?['ID']), concat('', items('Apply_to_each')?['Title'], ''))
One Step Minimised
Fair warning; if you're not going to use the unique characters I use below, test which ones don't parse well in flow, first, I found some that caused issues, like "æ".
So, in order to minimise the whole thing in to one step after the HTML creation, you can use the email section like this:
In the HTML table, use unlikely characters to wrap the ID and Title fields from SharePoint. I've used "ĐĐĐ", "œœœ", and "ĐœĐœĐ":
ĐĐĐ#{item()?['ID']}œœœ#{item()?['Title']}ĐœĐœĐ
In the email, go to the body, and ensure you have placed the following expression in the "Code view" (click the '</>' button), replacing:
[COMPANY] with your company sub-domain,
[SITE] with the relevant SharePoint site
[LISTNAME] with the relevant list name
replace(replace(replace(string, 'ĐĐĐ', ''), 'ĐœĐœĐ', '')
Apologies for my lack of clarity: we're both correct...I have the group by working as stated...but now I can't get my group by and your hyperlink solution working side by side. It looks like the issue is between the concat() in "Create HTML table" and/or replace() in the email body. I have tried to illustrate the issue further in the attachments, please refer to those. Thank you!
page 1 of issue;
page 2 of issue

Select specific text from specific span

I am trying to use python to scrape TripAdvisor and pull text from a specific span ---> <span>138<span> (without the Excellent)
<label for="taplc_prodp13n_hr_sur_review_filter_controls_0_filterRating_5">
<div class="row_label">Excellent</div>
<span class="row_bar">
<span class="row_fill" style="width:65%;"></span>
</span>
<span>138<span>
</span></span></label>
This is my code thus far:
for rating_all in moresoup.findAll('div',{'class':'col rating '}):
for record in rating_all.findAll('li'):
for rate1 in record.findAll('label',{'for':"taplc_prodp13n_hr_sur_review_filter_controls_0_filterRating_1"}):
print(rate1.find('div',{'class':"row_label"}).text + ",\t")
print(rate1.findAll('span'))
I tried using a subscript but it wouldn't let me. When I use the .text after the span it says there is no text, when I change it to find instead of find all it only finds the first span.
findAll (or more commonly find_all - which does the same thing) returns a list of all Tag objects matching your filters. Even if there is only one matching Tag you will still get a one-item list: [Tag].
Once you have the list of tags, you can get a single tag by indexing, e.g.:
soup.find_all('span')[0]
and you can get the text of one your tags with the .text attribute:
soup.find_all('span')[0].text
In your particular case, I was able to get the text '138\n' with:
rate1.findAll('span')[2].text

ExpressionEngine add class to wrap parameter

I have entries that contain an image as a channel entry field. I am using the following syntax in my template to generate an alt tag w/ data. The problem I have is that I haven't found a way to add a class attribute to the generated img tag.
{info-image wrap="image" class="img-responsive"}
outputs
<img src="http://secretproject.dev/images/uploads/general/dedication2.jpg" alt="dedication2">
where the alt data is the image title.
If I take another approach and write
<img class="img-responsive" src="{info-image}" alt="{title}">
then the title comes from the entry itself and not the file title.
In summary, I need both class and alt attributes but seem to be stuck with one or the other. Is there a way to achieve this in either syntax? Is there another approach? Thanks
You can use the variable pair syntax as described in the documentation.
{info-image}
<img src="{url}" alt="{title}" class="img-responsive">
{/info-image}

How to extract the hover box information in watir and print it to a STDOUT

I have to print the hover box information content on to stdout and i tried it in the below fashion it didn't work for me .
data = $browser.div(:class => "homeSectionLabel textWidget",:text => /Pool A/ ).hover
print "Data #{data} \n"
And the other problem that i have other widget called Pool B with same class name . How to access that hover information
<div class="widgetContainer poolContainer">
<div class="healthBadge healthUnknown" style="top: -5px; left: -5px;"></div>
<div class="homeSectionLabel textWidget">Pool‌·A</div>
<div class="perfDisplay homePoolPerf">
</div>
<div class="homePoolVolText textWidget">9‌·Volumes,‌·0‌·Snapshots</div>
<div class="spaceMeterContainer poolMeter" style="width: 265px; height: 20px;">
</div>
<table class="tableWidget homeTiers" cellspacing="0" cellpadding="0" border="0">
</table>
</div>
Anyhelp is really appreciated .
Thanks!
Aditya
This is not much of an answer at the moment, but what I have to say won't fit in a comment
The 'content' as in the text within a div is normally accessed with the .text method
'tooltip' text can be done in a number of ways, it could be via alt attributes, it could be via javascript triggered via an 'onmouseover' event, or it could be CSS driven usually via the :hover psuedoclass.
if a div is merely changing it's display property or location so that it becomes visible to the user, then all you need to do is figure out how to locate that div, and get the .text from it
mydata = browser.div(:how => 'what').text
If the content of the div (or some other container) is changing as a result of the mouseover/hover, then you need to simulate the action, wait a brief bit to allow client side code to run, and THEN get the .text from the container that was changed.
Without seeing a page that has the code working on it, it is hard to tell which is the case, although given that I see nothing like 'onmouseover' in the code you supplied, my first bet would be on this being CSS driven.
The code you have above is returning the result of the div object executing the .hover method, and that is going to be nil as far as I know since that method causes something to happen, but does NOT return a value.
Is the 'Pool A' the text you are trying to capture, or is it what you mouse_over to cause the other text to become visible to the user? If it is what you mouseover, then have you searched the HTML to see if you can find the text that appears in some other div?
If you just need to get the text from every div of a given class, then try something like this
browser.divs(:class => "homeSectionLabel textWidget").each do |div|
puts div.text
end
Based on the most recent comment, this will gather the class names from all of the divs on the page and print it to the console.
$browser.divs.each do |div|
puts div.class
end
Replace "puts div.class" with a file directive if you want it in a file. Any output here is simple Ruby.

Resources