Use Tampermonkey/Userscript to organise UL List - html

I am trying to order my search results using TamperMonkey/Userscript. The results start with Customer:, Case:, Inventory:, PNG:, etc. Below is HTML from the search results however I cannot find anyway to customise the order on these??
<div class="uir-tooltip-content"><ul id="uir-global-search-container" role="listbox" style="min-width: 550px; display: block;"><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=3904965" id="/app/common/media/mediaitem.nl?id=3904965">PNG Image: <span>Bank Transfer Receipt Thermo Invoice 67578.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=3904965&e=T" id="edit_/app/common/media/mediaitem.nl?id=3904965" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo Invoice 67578.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=4380864" id="/app/common/media/mediaitem.nl?id=4380864">PNG Image: <span>Bank Transfer Receipt Thermo Invoice 71546.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=4380864&e=T" id="edit_/app/common/media/mediaitem.nl?id=4380864" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo Invoice 71546.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=4230494" id="/app/common/media/mediaitem.nl?id=4230494">PNG Image: <span>Bank Transfer Receipt Thermo January Invoices.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=4230494&e=T" id="edit_/app/common/media/mediaitem.nl?id=4230494" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo January Invoices.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5049467" id="/app/common/media/mediaitem.nl?id=5049467">PDF File: <span>BOQ IB - Transfers & BPAY - Thermogroup.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5049467&e=T" id="edit_/app/common/media/mediaitem.nl?id=5049467" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY - Thermogroup.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5168179" id="/app/common/media/mediaitem.nl?id=5168179">PDF File: <span>BOQ IB - Transfers & BPAY THERMO.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5168179&e=T" id="edit_/app/common/media/mediaitem.nl?id=5168179" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY THERMO.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5661633" id="/app/common/media/mediaitem.nl?id=5661633">PDF File: <span>BOQ IB - Transfers & BPAY.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5661633&e=T" id="edit_/app/common/media/mediaitem.nl?id=5661633" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1056272" id="/app/crm/common/crm.nl?id=1056272">Case: <span>C10118 You've been sent the details of a NetBank tra... (3077 Ascot Bathroomware)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1056272&e=T" id="edit_/app/crm/common/crm.nl?id=1056272" aria-label="Edit Case:C10118 You've been sent the details of a NetBank tra... (3077 Ascot Bathroomware)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1262175" id="/app/crm/common/crm.nl?id=1262175">Case: <span>C12226 You've been sent the details of a NetBank tra... (2268 Tile Power Penrith)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1262175&e=T" id="edit_/app/crm/common/crm.nl?id=1262175" aria-label="Edit Case:C12226 You've been sent the details of a NetBank tra... (2268 Tile Power Penrith)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1395573" id="/app/crm/common/crm.nl?id=1395573">Case: <span>C13603 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1395573&e=T" id="edit_/app/crm/common/crm.nl?id=1395573" aria-label="Edit Case:C13603 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1624647" id="/app/crm/common/crm.nl?id=1624647">Case: <span>C15969 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1624647&e=T" id="edit_/app/crm/common/crm.nl?id=1624647" aria-label="Edit Case:C15969 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)">Edit</a></li><li><a id="showMoreItems" class="uir-item-view uir-global-search-more" href="/app/common/search/ubersearchresults.nl?Uber_NAME=transfer&quicksearch=T&searchtype=Uber&frame=be&Uber_NAMEtype=KEYWORDSTARTSWITH">Show more results</a></li></ul></div>

I guess it's not the best way to do it, but you could try something like this:
// ==UserScript==
// #name New Userscript
// #namespace http://tampermonkey.net/
// #version 0.1
// #description try to take over the world!
// #author You
// #match https://www.w3schools.com/jsref/dom_obj_document.asp
// #icon https://www.google.com/s2/favicons?domain=w3schools.com
// #grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
var UL = document.getElementById("uir-global-search-container");
if (UL.hasChildNodes()) {
var LIs = Array.from(UL.getElementsByClassName("uir-global-search-item"));
var newLIs;
LIs.forEach(li => {
UL.removeChild(li);
});
var moreLink = UL.lastChild;
UL.removeChild(moreLink);
LIs.forEach(li => {
if(li.innerHTML.includes("Customer:")) {UL.appendChild(li); }
});
LIs.forEach(li => {
if(li.innerHTML.includes("Case:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("Inventory:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("PNG Image:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("PDF File:")) UL.appendChild(li);
});
UL.appendChild(moreLink);
}
})();

Related

How to convert Text(with breakline) to display properly on HTML textbox

Kemandirian spesies ialah keupayaan haiwan dan tumbuhan untuk mengekalkan spesiesnya bagi mengelakkan kepupusan.
Ciri dan tingkah laku khas haiwan untuk melindungi diri daripada musuh seperti:
(i) Memutuskan anggota badan;
(ii) Menyembur dakwat hitam;
(iii) Mempunyai mata palsu.
Galakkan penggunaan TMK untuk membuat pemerhatian pelbagai ciri dan tingkah laku khas haiwan untuk melindungi diri.
let's say that i have this text and i save it to database , but when i tried to pull it out from database , it just show everything in a single line , what's is the best way to keep the original format ?
You can change all \n characters to <br> and then upload to your DB.
When you fetch your data then you can convert all the <br> tags to \n character.
let x = `Kemandirian spesies ialah keupayaan haiwan dan tumbuhan untuk mengekalkan spesiesnya bagi mengelakkan kepupusan.
Ciri dan tingkah laku khas haiwan untuk melindungi diri daripada musuh seperti:
(i) Memutuskan anggota badan;
(ii) Menyembur dakwat hitam;
(iii) Mempunyai mata palsu.
Galakkan penggunaan TMK untuk membuat pemerhatian pelbagai ciri dan tingkah laku khas haiwan untuk melindungi diri.`;
let withBR = x.replace(/\n/gm, "<br>");
console.log("Upload To DB \n\n");
console.log(withBR);
// Upload To The DB
// ----------------------------------------------------------
// On Fetch Starts
let originalText = withBR.replace(/\<br\>/gm, "\n")
console.log("Original Text \n\n");
console.log(originalText);
Hope it helps.

how to select a custome dropdown option in Playwright UI test

I am doing end to end UI testing and when I try to select an option for Harmony web UI component (<ext-support_he-select>), playwright is not able to recognize the custome tag and it error out saying not a select option.
And I am not able to record dropdown select option with Headless Recorder as well, could you please let me know if anybody has come across this kind of issue.
HTML Select Code :
{
<ext-support_he-select id="workspace-dropdown" class="basic-dropdown basic-workspace-dropdown below valid" aria-labelledby="workspace-label" role="combobox" current-value="" aria-controls="" aria-disabled="false" aria-expanded="false" aria-haspopup="listbox" tabindex="0" position="below" aria-activedescendant="option-14">
<ext-support_he-option selected="" value="" aria-selected="true" class="selected" role="option" id="option-14" aria-posinset="1" aria-setsize="9"> Select a Workspace </ext-support_he-option>
<ext-support_he-option value="accountPlans" aria-selected="false" role="option" id="option-15" aria-posinset="2" aria-setsize="9"> Account Plans </ext-support_he-option>
<ext-support_he-option value="accounts" aria-selected="false" role="option" id="option-16" aria-posinset="3" aria-setsize="9"> Accounts </ext-support_he-option>
<ext-support_he-option value="contacts" aria-selected="false" role="option" id="option-17" aria-posinset="4" aria-setsize="9"> Contacts </ext-support_he-option>
<ext-support_he-option value="engagements" aria-selected="false" role="option" id="option-18" aria-posinset="5" aria-setsize="9"> Engagements </ext-support_he-option>
<ext-support_he-option value="leads" aria-selected="false" role="option" id="option-19" aria-posinset="6" aria-setsize="9"> Leads </ext-support_he-option>
<ext-support_he-option value="opportunities" aria-selected="false" role="option" id="option-20" aria-posinset="7" aria-setsize="9"> Opportunities </ext-support_he-option>
<ext-support_he-option value="partners" aria-selected="false" role="option" id="option-21" aria-posinset="8" aria-setsize="9"> Partners </ext-support_he-option>
<ext-support_he-option value="userProvisioning" aria-selected="false" role="option" id="option-22" aria-posinset="9" aria-setsize="9"> User Provisioning </ext-support_he-option>
<!--fast-eovm3s:5-->
</ext-support_he-select> }
Please refer UI screenshot given below.
You can use first click on the dropdown and the click on the required dropdown item.
await page.locator(#workspace-dropdown).Click();
await page.waitForSelector("xpath=//ext-support_he-option[#value='accounts'");
await page.locator("xpath=//ext-support_he-option[#value='accounts'").Click();
Yes, I got that hint from my friend as well, and this works instead of using the "select option" call. Just I putting my code as a reference if someone wants to use this.
var workSpaceDropdown = page.locator('#workspace-dropdown');
await workSpaceDropdown.click();
page.keyboard.press('ArrowDown');
please refer below for more details.
https://playwright.dev/docs/api/class-keyboard#keyboard-down

Attempting to click on a child hyperlink with puppeteer js

I have the following html:
<td id="content_PDB_Dashboard_UC_SharedLeads_gvSharedLeads_tccell0_6" class="dxgv dx-ellipsis" align="left" style="border-bottom-width:0px;" title="
1905 Saint Louis Avenue
" dxellipsistitle="true">
<a onclick="return ShowCallDialog(472919, 7);">1905 Saint Louis Avenue </a>
</td>
There are multiple of these on a page. I need to loop through and click on each link. The 'a'.
Here is my attempt:
const allProperties = await page.$$('.dxgv, .dx-ellipsis > a');
allProperties.map(el => {
el.click();
})
The error I receive is:
Error: Node is either not visible or not an HTMLElement
Any idea what I'm doing wrong?
map doesn't execute asynchronously, replace it with a simple for loop or Promise.all.
if there is no constraint on using HTMLElement.click, use that instead (issue).
const anchors = await page.$$('.dxgv, .dx-ellipsis > a');
for (let anchor of anchors)
await page.evaluate(el => el.click(), anchor);

How to conditionally format test based on status of a form?

I am trying to get my form to show red text when the form is invalid and green when the form is valid based on the status of the form and the validation criteria. How can this be achieved through angular 8?
(HTML)
<p class="status">
Form Status: {{ Form.status }}
</p>
(TS)
Form = this.fb.group({
Id: [0],
name: ['', Validators.required],
app: ['', Validators.required],
domain: [''],
environment: ['']
})
create invalid-class CSS and adjust your html to:
<p class="status">
Form Status:
<span [class.invalid-class]="Form.invalid">
{{ Form.status }}
</span>
</p>

How to Change output text with selective options in html tag

I have this code :
<ul class="quick-contact">
<li class="phone"><strong>Sales: </strong>0987 989898</li>
<li class="email"><strong>Email: </strong>info#yourdomain.com</li>
<li class="sites"><strong>Sites: </strong><select class="inputbox"><option>USA</option><option>UK</option><option>France</option><option>Japan</option><option>South Africa</option></select></li>
</ul>
I want sales number change with each options selected.
If someone has any ideas I really appreciate all answers
You will need to make use of Javascript to achieve this functionality.
Working Snippet:
// comments inline
var salesNumbers = { // store all phone numbers in an object here
'USA': '123 123', // you can easily add/remove/modify the country/numbers here
'UK': '456 456',
'France': '789 789',
'Japan': '111 222',
'South Africa': '333 444'
}
function updateSalesNumber(){ // this will be called when dropdown value will be changed
var inputBox = document.getElementById("inputbox");
// get the selected option
var selectedOption = inputBox.options[inputBox.selectedIndex].value;
// update the number on the webpage
document.getElementById("sales-number").innerHTML = salesNumbers[selectedOption];
}
<ul class="quick-contact">
<li class="phone"><strong>Sales: </strong><span id="sales-number">0987 989898</span></li>
<li class="email"><strong>Email: </strong>info#yourdomain.com</li>
<li class="sites"><strong>Sites: </strong>
<select id="inputbox" onchange="updateSalesNumber()">
<option value="USA">USA</option>
<option value="USA">UK</option>
<option value="France">France</option>
<option value="Japan">Japan</option>
<option value="South Africa">South Africa</option>
</select>
</li>
</ul>
You will need to use javascript or jQuery to do what you want to do. This is the only way to manipulate values in the DOM.
Different people will give you different answers. But here is one simple option using jQuery.
I have written a jQuery example but if you need a pure javascript one let me know.
Basically you need a value on all your options which contains the phone number that corresponds to it. (e.g USA and a value for it's phone number).
When the select box is changed it updates the sale number. I have added an extra span with a class to make it easier to update.
http://jsfiddle.net/williamtdavies/6621wd1j/
<ul class="quick-contact">
<li class="phone"><strong>Sales: </strong><span class="phone__number">0987 989898</span></li>
<li class="email"><strong>Email: </strong>info#yourdomain.com</li>
<li class="sites"><strong>Sites: </strong><select class="inputbox"><option value="123">USA</option><option value="456">UK</option><option value="789">France</option><option value="101112">Japan</option><option value="131415">South Africa</option></select></li>
</ul>
// Function to update the sales phone number
function changePhoneNumber(phoneNumber){
// Writes HTML into the span with class "phone__number"
$('.phone__number').html(phoneNumber);
}
// Change event calls the function to update the sales number
// Passes the new value after change into the function
$('.inputbox').on('change', function(){
var phoneNumber = $(this).val();
changePhoneNumber(phoneNumber);
});
// Calls the function on load in case the select box selection has remained from a previous change
$(document).ready(function(){
changePhoneNumber($('.inputbox').val());
});
Include jQuery and use below js
var inputBox = $(".inputbox"),
countryNumber = $('#country-number');
console.log(inputBox.length);
function updateSalesNumber(){
countryNumber.text(inputBox.val());
}
inputBox.on('change', function(){
updateSalesNumber();
})
Use below html...
<ul class="quick-contact">
<li class="phone"><strong>Sales: </strong> <span id="country-number">0987 989898</span></li>
<li class="email"><strong>Email: </strong>info#yourdomain.com</li>
<li class="sites"><strong>Sites: </strong><select class="inputbox"><option value="111111">USA</option><option value="222222">UK</option><option value="333333">France</option><option value="444444">Japan</option><option value="555555">South Africa</option></select></li>
</ul>