How to drag and drop the angular element using co-ordinates in Robot Framework - selenium

I am trying to automate this angular application using the Robot Framework.
I am trying to drag and drop the rectangle using the drag and drop by offset keyword.
The manual scenario is when I click on the middle of the rectangle and drag, it drags the arrow.The code changes to <g transform="translate(0.5,0.5)" style="visibility: visible; cursor: pointer;"> .
If I drag through the edges, the rectangle will be moveable and the code changes to <g transform=" translate(0.5,0.5)" style=" visibility: visible; cursor: move;
I would like to drag and drop the rectangle by clicking sides. All the xpaths I tried are clicking in middle and dragging the arrow.
Please if anyone knows how to write xpath using SVG, please help me out.
<svg style="width: 100%; height: 100%; display: block; min-width: 1081px; min-height: 384px;">
<g>
<g></g>
<g>
<g transform="translate(0.5,0.5)" style="visibility: visible;">
<ellipse cx="132" cy="132" rx="32" ry="32" fill="black" stroke="black" transform="translate(0,3)" opacity="0.2"></ellipse>
<ellipse cx="132" cy="132" rx="32" ry="32" fill="#f5f5f5" stroke="#f5f5f5" pointer-events="all"></ellipse>
</g>
<g style="">
<g fill="#000000" font-family="Roboto" font-weight="bold" text-anchor="middle" font-size="14px">
<text x="132" y="137">New</text>
</g>
</g>
<g transform="translate(0.5,0.5)" style="visibility: visible; cursor: move;">
<rect x="960" y="300" width="120" height="80" fill="black" stroke="black" transform="translate(0,3)" opacity="0.2"></rect>
<rect x="960" y="300" width="120" height="80" fill="#2196f3" stroke="#2196f3" pointer-events="all"></rect>
</g>
<g style="cursor: move;">
<g fill="#000000" font-family="Roboto" font-weight="bold" text-anchor="middle" font-size="14px">
<text x="1020" y="345">test</text>
</g>
</g>
</g>
<g></g>
<g></g>
</g>
</svg>
I have tried many xpaths. But none of them helping me drag the rectangle. All the xpaths I tried are clicking in between the rectangle and results in an arrow.
Some of the xpaths tried:
(//[name()='svg']///)[3]
(//[local-name()='svg']//[name()='g'])[7]//*[local-name()='rect'][1]
(//[local-name()='svg']//[name()='g'])[7]//*[local-name()='rect'][2]
Thanks in advance.

The default Selenium behavior is to click on the center of the element.
For this I would use java.awt.Robot
In Java it would be something in the lines of
Robot r = new Robot();
Point p = findElement(locator).getLocation();
r.mouseMove(p.x + someXOffsetFromTheCenter, p.y + someYOffsetFromTheCenter);
//then use Actions to drag and drop to the destination (you should determine the destination the same way as the origin - [x,y])
Actions action = new Actions(driver);
action.click().moveByOffset(x,y).release().build().perform();
//alternatively, if you can drop to the center of the destination element, you could do
action.click().moveToElement(destinationElem).release().build().perform();

Related

hover on svg in cypress and test tooltip

Scenario:
I have something similar
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<!-- Using g to inherit presentation attributes -->
<g fill="white" stroke="green" stroke-width="5">
<circle cx="40" cy="40" r="25" />
<circle cx="60" cy="60" r="25" />
</g>
</svg>
Hovering over svg will show a tooltip and I need to test whether tooltip is displayed and the content is correct.
Any suggestions? Tried trigger(mouseover) which in not working
cy.get(svg).trigger('focus')
worked for me

How to make an Ionic v4 custom tab icon change color when active?

I can get the custom icon to show up on the tab. However, it doesn't change color when you click it. The tab icon should go from the inactive gray to the active blue.
Tabs.html
<ion-tab-button tab="topics">
<ion-icon src="/assets/simple-path.svg"></ion-icon>
</ion-tab-button>
A simple svg
<svg width="39" height="45" viewBox="0 0 39 45" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 35L15 0.5L39 15.5L25 45L0 35Z" fill="#C4C4C4"/>
</svg>
tabs.scss
path {
--color: gray;
--color-selected: blue;
}
I was stuck on this for awhile. It turns out you need to remove the fill attributes from the svg like this:
<svg width="39" height="45" viewBox="0 0 39 45" xmlns="http://www.w3.org/2000/svg">
<path d="M0 35L15 0.5L39 15.5L25 45L0 35Z"/>
</svg>

How to center element inside SVG polygon

I have SVG that is assembled from multiple polygons.
I am trying to put image/button inside polygon center but what ever I try it always put image in x=0 and y=0 of the screen.
<Svg width="546px" height="794px" viewBox="0 0 546 794" version="1.1" >
<G id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<G id="item0" transform="translate(1.000000, 1.000000)" fill="#EDAF51" fill-rule="nonzero" stroke="#720D00">
<Polygon id="RX-03" points="206.65269...">
</Polygon>
<Circle x="0" y="0" cx="40" cy="40" r="15" fill="black" />
</G>
With this I get:
But if I put <Circle x="110" y="0" I get
And this is correct but I don't want to use x=110 I am trying to make this circle to be relative to it's parent polygon.
So I can set circle to x=0 y=0 and to keep it inside area of parent polygon.
New answer on the comment of the author of the question
In svg, with mutual positioning between elements, there is only absolute positioning.
Relative positioning in svg, as you want - there is no circle relative to the parent polygon.
Only absolute positioning of a circle will help to place it in the right place
You can create a circle once and clone it several times while positioning:
<use xlink:href="#crc1" x="100" y="150" />
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="546px" height="794px" viewBox="0 0 546 794" >
<defs>
<circle id="crc1" cx="0" cy="0" r="15" stroke="red" />
</defs>
<image transform="translate(0, -300)" xlink:href="https://i.stack.imgur.com/q0PXl.png"
width="100%" height="100%"
/>
<use xlink:href="#crc1" x="100" y="150" />
<use xlink:href="#crc1" x="210" y="110" />
<use xlink:href="#crc1" x="300" y="190" />
<use xlink:href="#crc1" x="385" y="190" />
<use xlink:href="#crc1" x="500" y="190" />
</svg>
</div>
An image can be inserted into any SVG shape in several ways:
Using clipPath
Using mask
Using pattern
With any method of inserting an image, you need to focus on the shape of the template.
If the template has a symmetrical shape, it is necessary to select the original image with the same aspect ratio.
In other words, if the cropping pattern is a circle or regular polygons, then you need to select images with the same width and height.
I translated the React syntax into the regular SVG syntax. If necessary, you can go back
Selected round image badge
Insert this image into the hexagon`
1. Using clipPath
The hexagon acts as a cropping pattern.
<style>
.container {
width:50%;
height:50%;
}
</style>
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 546 794" >
<defs>
<clipPath id="clip">
<path fill="none" stroke="none" stroke-width="2" d="m275.9 190.9 175.6 101.4 0 202.7-175.6 101.4-175.6-101.4 0-202.7z" />
</clipPath>
</defs>
<image xlink:href="https://i.stack.imgur.com/gOrJU.png"
x="0"y="0"
width="100%" height="100%"
clip-path="url(#clip)" />
</svg>
</div>
2. Using mask
.container {
width:50%;
height:50%;
}
image {
mask:url(#msk1);
}
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 546 794" >
<defs>
<mask id="msk1">
<path fill="white" stroke="red" stroke-width="12" d="m275.9 190.9 175.6 101.4 0 202.7-175.6 101.4-175.6-101.4 0-202.7z" />
</mask>
</defs>
<image xlink:href="https://i.stack.imgur.com/gOrJU.png" x="0" y="0" width="100%" height="100%" />
</svg>
</div>
3. Using pattern
.container {
width:50%;
height:50%;
}
path {
fill:url(#ptn1);
stroke:#DBC176;
stroke-width:8;
}
<div class="container">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 546 794" >
<defs>
<pattern id="ptn1" width="1" height="1">
<image xlink:href="https://i.stack.imgur.com/gOrJU.png" x="-24" y="3" width="400px" height="400px" />
</pattern>
</defs>
<path d="m275.9 190.9 175.6 101.4 0 202.7-175.6 101.4-175.6-101.4 0-202.7z" />
</svg>
</div>

SVG -> TCPDF gradient mismatch

I have the following SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="800" height="150" viewBox="0 0 800 150" xml:space="preserve">
<linearGradient id="SVGID_0" gradientUnits="userSpaceOnUse" x1="-400" y1="-150" x2="-400" y2="0">
<stop offset="0%" style="stop-color:rgb(255,64,64);stop-opacity: 1"/>
<stop offset="100%" style="stop-color:rgb(230,57,155);stop-opacity: 1"/>
</linearGradient>
<rect x="-400" y="-75" rx="0" ry="0" width="800" height="150" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: url(#SVGID_0); fill-rule: nonzero; opacity: 1;" transform="translate(400.5 75.5)"/>
</svg>
I am converting this to PDF using TCPDF:
$pdf->ImageSVG($file='images/testsvg.svg', $x=0, $y=0, $w='', $h='', $align='', $palign='', $border=0, $fitonpage=true);
As you can see from the image below, the gradient is applied wrongly.
Based on the illustrator image, it seems like TCPDF applies the center of the gradient to the bottom edge. If I manually move the center to the top edge then it looks very close to the original.
Any idea how I can fix this?
I think it's because of how the rect is positioned. It actually starts outside the viewbox and then both the gradient and the box get transformed. For example the box and the gradient x parameter are both -400. This is overly complex and I think some of the parameters are getting cancelled out by the $fitonpage=true parameter or the translations are being applied differently:
<rect x="-400" y="-75" rx="0" ry="0" width="800" height="150" style="... transform="translate(400.5 75.5)"/>
Based on the supplied examples there isn't really any point to this trickery. The only purpose appears to be modifying the gradient start and end colors. I would just move the rect to start at 0,0, remove the transforms, and then modify the gradient colors and stops to achieve the same effect the correct way:
<linearGradient y2="150" x2="0" y1="0" x1="0" gradientUnits="userSpaceOnUse" id="SVGID_0">
<stop
style="stop-color:#f13c73;stop-opacity:1"
id="stop4139"
offset="0" />
<stop
style="stop-color:#e6399b;stop-opacity:1"
id="stop4141"
offset="0.40" />
</linearGradient>
<rect
id="rect4143"
style="opacity:1;fill:url(#SVGID_0);fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none"
height="150"
width="800"
ry="0"
rx="0"
y="0"
x="0" />
The changes that matter are the removal of all the strange negative offsets on the rect and gradient and the change of the gradient stop colors and position to recreate the same gradient without the need to use cropping and transforms.

vb.net Selenium Webdriver findelement

Please understand that i'm not good at english.
There is a page that contains many rect in svg
I upload this page's html source .
There is a rect like this
<rect x="1720.68" y="726.97" width="11" height="11" rx="0" ry="0" fill="#bca888" stroke="#000" stroke-width="0" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></rect>
and There is a rect like that
<rect x="1707.36" y="646.85" width="11" height="11" rx="0" ry="0" fill="#dddddd" stroke="#000" stroke-width="0" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></rect>
But These rects are in svg
<svg height="526" version="1.1" width="682" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="1478.4759521484375 577.7315063476562 317.18333435058594 197.59629821777344" preserveAspectRatio="xMidYMin meet" style="overflow: hidden; position: relative; background-color: rgb(244, 244, 244);">
I want to program that click rect filled with "#baa882 color"
I tried to findelement by CssSelector, but it's too slow to use.
(I wanna fast program that Find Element immediately.)
Moreover, There is no way to work findelement by id or tagname.
(Please let me know if there is any available method.)
How can I make a program on condition?