Puppeteer (PuppeteerSharp) How to click? - puppeteer

How to click on an element if all id's are random?
Unique - only text with description.
This is a list that contains various items that you can click with the mouse. I can't figure out how to make this click, for example, on an element containing the text "Some Unique Text 3"
<section class="css-1kyhqub">
<ul data-testid="categories-list" data-cy="categories-list" class="css-jfja6s">
<li data-cy="cy-im-parent" class="css-xedlmo">
<div class="css-17fti8"><span>
<p class="css-1jek2ew-Text eu5v0x0">Some Unique Text 1</p></span>
<span font-size="p4" class="css-my4n3k"></span>
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1em" height="1em" class="css-1mougrc">
</svg></li><li data-cy="cy-im-parent" class="css-xedlmo">
<div class="css-17fti8"><span><p class="css-1jek2ew-Text eu5v0x0">Some Unique Text 2</p></span>
<span font-size="p4" class="css-my4n3k"></span></div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1em" height="1em" class="css-1mougrc">
</svg></li>
<li data-cy="cy-im-child" data-testid="nested-category-item" class="css-12lzvy8">
<div class="css-19rredd">
<section class="css-u2ayx9">
<p class="css-1jek2ew-Text eu5v0x0">Some Unique Text 3</p>
</section>
<span font-size="p4" class="css-6zq905"></span></div></li>
<li data-cy="cy-im-parent" class="css-xedlmo">
<div class="css-17fti8"><span><p class="css-1jek2ew-Text eu5v0x0">Some Unique Text 4</p></span>
<span font-size="p4" class="css-my4n3k"></span></div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1em" height="1em" class="css-1mougrc">
</li><li data-cy="cy-im-child" data-testid="nested-category-item" class="css-12lzvy8">
<div class="css-19rredd">
<section class="css-u2ayx9">
<p class="css-1jek2ew-Text eu5v0x0">Some Unique Text 5</p>
</section>
<span font-size="p4" class="css-6zq905"></span></div></li></ul>
</section>
Any idea?

You can try this if you only want to click on one paragraph element containing specific text.
await page.evaluate(() => {
const elements = [...document.querySelectorAll('p')];
const targetElement = elements.find(e => e.innerText == 'Some Unique Text 3');
if (targetElement) targetElement.click();
});
Or if you want to click on multiple paragraph elements containing specific text try this.
await page.evaluate(() => {
Array.from(document.querySelectorAll('p')).filter(p => {
return p.innerText == 'Some Unique Text 3'
}).forEach(element => {
if (element) element.click();
});
});

Related

I seem to be having an issue with navigation bar turning in-to random colors that I've not set

Alright, so my navigation bar used to be looking like this a few days ago:
But once I try to center the navigation bar to the middle, it turns in-to random colors and the spaces between the interactable buttons disappeared as shown in this picture:
I just tried to debug it and apparently it only happens when I put the display to inline-block. Am I doing anything wrong?
My CSS for the navigation bar:
.topnav {
background-color: #ffffff;
overflow: hidden;
}
.topnav a {
float: center;
color: #000000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
My HTML for the navigation bar:
<div class="topnav">
<i class="fab fa-facebook-square" style="font-size: 30px"></i>
<i class="fa-solid fa-book" style="font-size: 30px"></i>
<i class="fa-solid fa-pen-to-square" style="font-size: 30px"></i>
<i class="fa-solid fa-user-graduate" style="font-size: 30px"></i>
<i class="fa-solid fa-house-chimney" style="font-size: 30px"></i>
</div>
I removed the links for security reasons.
this happens because the <svg> if nested inside <a> will behave like a link...
you know that a link with a text inside is always blue and with an underline
just color the SVG to the color you want, to solve the bug
I created a demo in a jfiddle, so you can try and learn :)
I hope it will help you, and learned something new
body svg {
width: 5em;
}
/* color the svg, for not having this bug */
.with-success svg {
color: black;
}
<div class="with-error">
<h2>with error</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>
<hr>
<div class="with-success">
<h2>success</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>

How to make the width fit to the content when text wrapped? [duplicate]

This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
CSS when inline-block elements line-break, parent wrapper does not fit new width
(2 answers)
Closed 1 year ago.
I'm using tailwind to create a card with an arrow. I want the arrow always next to the text 10px. But when the text is wrapped, the width of the text is larger than the actual width of the text.
I tried adding width: fit-content but the text will overflow and can't wrap. If I add width: min-content then the text always wraps.
I must use javascript to get the actually width of the text in this case, right?
Here is my code:
<div class="grid grid-cols-3 gap-8 m-20 lg:max-w-[1200px]">
<div class="w-full h-52 overflow-hidden shadow-xl p-8 flex items-center justify-start gap-4">
<div class="min-w-[80px] min-h-[80px] bg-blue-500"></div>
<p class="text-xl font-bold">Software Solutions</p>
<svg width="7" height="12" viewBox="0 0 7 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.78125 0.75L6.25 5.5C6.375 5.65625 6.46875 5.84375 6.46875 6C6.46875 6.1875 6.375 6.375 6.25 6.53125L1.78125 11.2812C1.5 11.5938 1.03125 11.5938 0.71875 11.3125C0.40625 11.0312 0.40625 10.5625 0.6875 10.25L4.6875 6L0.6875 1.78125C0.40625 1.46875 0.40625 1 0.71875 0.71875C1.03125 0.4375 1.5 0.4375 1.78125 0.75Z" fill="#333940" />
</svg>
</div>
<div class="w-full h-52 overflow-hidden shadow-xl p-8 flex items-center justify-start gap-4">
<div class="min-w-[80px] min-h-[80px] bg-blue-500"></div>
<p class="text-xl font-bold pr-0 w-[fit-content]">Business process solutions</p>
<svg width="7" height="12" viewBox="0 0 7 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.78125 0.75L6.25 5.5C6.375 5.65625 6.46875 5.84375 6.46875 6C6.46875 6.1875 6.375 6.375 6.25 6.53125L1.78125 11.2812C1.5 11.5938 1.03125 11.5938 0.71875 11.3125C0.40625 11.0312 0.40625 10.5625 0.6875 10.25L4.6875 6L0.6875 1.78125C0.40625 1.46875 0.40625 1 0.71875 0.71875C1.03125 0.4375 1.5 0.4375 1.78125 0.75Z" fill="#333940" />
</svg>
</div>
</div>
Edited
I don't think that this is possible with CSS alone.
See this answer for JS fix: https://stackoverflow.com/a/32222395/4536543
Here's my take on it:
// get list of all spans
list = document.querySelectorAll('.content span');
for (var i=0; i<list.length; i++) {
// retrieve width of span and apply it to parent
w = list[i].offsetWidth;
list[i].parentNode.style.width = w+1+"px"; // need to add 1 because sometimes width is not a whole number and Browser sometimes rounds it down which will trigger layout shift
}
<div style="background: green; width: 134px; position: relative">
<div class="content" style="background: yellow; float: left; max-width: 124px;">
<span style="background: grey">
somewhat long text goes here <!-- this is your "Business process solutions" -->
</span>
</div>
<div style="background: red; width: 10px; display: inline">
>
</div> <!-- this is your arrow -->
</div>

SVG Doesn't show up in button element

I'm using inline SVG ( as JSX ) on my website, I'm trying to display a hamburger menu button but it isn't showing up. Here is my code:
import Link from "next/link"
function Nav() {
return (
<nav>
<button > /// SVG is here
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-172 -12 210 50" stroke="#000000">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
</svg>
</button>
<ul className="">
<li>
<Link href="/">
<a>Main</a>
</Link>
</li>
<li>
<Link href="/resume">
<a>Resume</a>
</Link>
</li>
<li>
<Link href="/projects">
<a>Projects</a>
</Link>
</li>
<li>
<Link href="/blog">
<a>Blog</a>
</Link>
</li>
<li>
<Link href="/contact">
<a>Get in touch</a>
</Link>
</li>
</ul>
</nav>
);
}
export default Nav;
The Icon is only visible when it's outside the button tag, how do I view it while preserving the viewBox attribute?
In your case you need to adjust the viewBox for your svg element, that way when you set your svg's height and width, your svg scales properly and you get the desired result. Here's your code which I tweaked:
<button>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 1 20 20" stroke="#000000" height="50px" width="50px">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
</svg>
</button>
See it work on codepen here.
You can learn about how viewBox works at CSS tricks and MDN.

How to design totally different templates for different devices, like mobile and desktop, but also tablet in Angular?

So I have a angular 9 application.
And I have some mockups. But the template on mobile looks totally different then on dekstop.
But the data(API calls) are almost identical on both(desktop, mobile). Almost. So it even can differ for mobile and for desktop.
But so my question. Is this the best 'approach'? Or is it better to work with media queries?
So this is for desktop:
<!-- <app-bar-chart></app-bar-chart> -->
<div>
<router-outlet></router-outlet>
</div>
<div class="w-100 d-lg-block d-md-block">
<div class="d-none d-lg-block d-md-block">
<mat-grid-list cols="4" rowHeight="1:2">
<mat-grid-tile colspan="1">
<div class="nested-grid-list">
<mat-grid-list cols="1" rowHeight="3:2">
<mat-grid-tile *ngFor="let card of cards; let i = index;" [colspan]="card.cols" [rowspan]="card.rows">
<cdk-drop-list [cdkDropListConnectedTo]="drops" [cdkDropListData]="i">
<mat-card cdkDrag (cdkDragEntered)="entered($event)" [cdkDragData]="i" class="dashboard-card"
[style.backgroundColor]="card.color">
<mat-card-content class="dashboard-card-content">
<div class="example-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path
d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z">
</path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
</mat-card-content>jhjhjhj
</mat-card>
</cdk-drop-list>
</mat-grid-tile>
</mat-grid-list>
</div>
</mat-grid-tile>
<mat-grid-tile colspan="2">
<div class="nested-grid-list">
<mat-grid-list cols="1" rowHeight="3:1">
<mat-grid-tile *ngFor="let card of cards2; let i = index;" [colspan]="card.cols" [rowspan]="card.rows">
<cdk-drop-list [cdkDropListConnectedTo]="drops" [cdkDropListData]="i">
<mat-card cdkDrag (cdkDragEntered)="entered2($event)" [cdkDragData]="i" class="dashboard-card"
[style.backgroundColor]="card.color">
<mat-card-content class="dashboard-card-content">
<div class="example-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path
d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z">
</path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
</mat-card-content>
</mat-card>
</cdk-drop-list>
</mat-grid-tile>
</mat-grid-list>
</div>
</mat-grid-tile>
<mat-grid-tile colspan="1">
<div class="nested-grid-list">
<mat-grid-list cols="1" rowHeight="3:2">
<mat-grid-tile *ngFor="let card of cards3; let i = index;" [colspan]="card.cols" [rowspan]="card.rows">
<cdk-drop-list [cdkDropListConnectedTo]="drops" [cdkDropListData]="i">
<mat-card cdkDrag (cdkDragEntered)="entered3($event)" [cdkDragData]="i" class="dashboard-card"
[style.backgroundColor]="card.color">
<mat-card-content class="dashboard-card-content">
<div class="example-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path
d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z">
</path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
</mat-card-content>
</mat-card>
</cdk-drop-list>
</mat-grid-tile>
</mat-grid-list>
</div>
</mat-grid-tile>
</mat-grid-list>
</div>
</div>
And this is for mobile:
<div class="d-flex flex-column d-block d-sm-none">
<div style="height: 50vh">
<app-map-element></app-map-element>
</div>
<div style="height: 50vh">
<app-list></app-list>
</div>
</div>
and map component looks like this:
<div id="map" class="map"></div>
<form class="form-inline">
<label>Measurement type </label>
<select id="type">
<option value="length">Length (LineString)</option>
<option value="area">Area (Polygon)</option>
</select>
</form>
So any suggestions, would be nice.
Thank you
Or maybe two different applications with sharing API calls?
Just giving you simple adhoc ways is three different blocks of code for different devices and you can initiate them in different ways,
Easiest way is using a plugin ngx-device-detector.
Use the variable in *ngIf cases and load the block only when the device is true.
This actually doesn't load the unnecessary data.
Use media queries (this just hides data) CSS change.
Bootstrap is the way to go. You should check it out

Pause video on slide

I want to pause the VIDEO when I slide by dragging or using slide next, prev buttons.
It doesn't matter which slider. it can be useful-swiper or owl-carousel
I'm using ngx-useful-swiper as my Carousel.
I can use ngx-owl-carousel-o instead, But if it worked with anyone
My HTML
<swiper [config]="heroSlider" #usefulSwiper>
<div class="swiper-wrapper">
<div class="swiper-slide text-center" *ngFor="let item of sections.about_video; index as i">
<video
poster="{{ fileUrl + item.thumbnail }}"
playsinline
autoplay="false"
muted
controls="false"
onloadedmetadata="this.muted = true"
src="{{ fileUrl + item.video }}"
id="video"
#video
></video>
</div>
</div>
<button class="btn p-0 btn-prev" (click)="previousSlide()">
<svg
version="1.1"
id="Layer_1"
x="0px"
y="0px"
viewBox="0 0 26 43"
style="enable-background: new 0 0 26 43"
xml:space="preserve"
>
<path
id="Path_3540"
class="st0"
d="M21.5,43c2.5,0,4.5-2,4.5-4.5c0-1.2-0.5-2.4-1.3-3.2L10.9,21.5L24.7,7.7
c1.7-1.8,1.7-4.7-0.1-6.4c-1.8-1.7-4.5-1.7-6.3,0l-16.9,17c-1.8,1.8-1.8,4.6,0,6.4l16.9,17C19.1,42.5,20.3,43,21.5,43z"
/>
</svg>
</button>
<button class="btn p-0 btn-next" (click)="nextSlide()">
<svg
class="icon"
version="1.1"
id="Layer_1"
x="0px"
y="0px"
viewBox="0 0 26 43"
style="enable-background: new 0 0 26 43"
xml:space="preserve"
>
<path
id="Path_3539"
class="st0"
d="M4.5,43C2,43,0,41,0,38.5c0-1.2,0.5-2.4,1.3-3.2l13.7-13.8L1.3,7.7c-1.7-1.8-1.7-4.7,0.1-6.4c1.8-1.7,4.5-1.7,6.3,0l16.9,17c1.8,1.8,1.8,4.6,0,6.4l-16.9,17C6.9,42.5,5.7,43,4.5,43z"
/>
</svg>
</button>
</swiper>
My TS
heroSlider: SwiperOptions = {
loop: false,
slidesPerView: 1,
on: {
transitionEnd: function (Swiper) {
console.log(Swiper);
},
},
};
If you simply mean you want to pause video when you click the next or previous buttons, you can add a listener for those buttons and in that listener pause the video.
Some example below showing adding an ID to the button and then using this to find the button in your Javascript and add a listener.
You can add a resume button also or just have the user click play on the video.
<button id="btnNext" class="btn p-0 btn-prev" (click)="previousSlide()">
var vid1 = document.getElementById("YourVideoID");
var btnNext = document.getElementById("NextButton");
var btnPrev = document.getElementById("PrevButton");
var btnResume = document.getElementById("PrevButton");
btnNext.addEventListener("click", function() {
vid1.pause()
});
btnPrev.addEventListener("click", function() {
vid1.pause()
});
btnResume.addEventListener("click", function() {
vid1.play()
});