I am attempting to drag a specific Webelement and drop it inside an SVG "container" that contains four elements, which are represented by polygons. Each polygon is labeled as g[1], g[2], and so on.
Here is the HTML code of the container:
<div class="leaflet-overlay-pane"><img class="leaflet-image-layer leaflet-
zoom-animated" src="/ik-conf/layout/Planos1544448485901.png" style="opacity:
1; transform: translate3d(509px, 280px, 0px); width: 524px; height: 348px;">
<svg class="leaflet-zoom-animated" width="1472" height="855" viewBox="35 26
1472 855" style="transform: translate3d(35px, 26px, 0px);">
<g><path stroke-linejoin="round" stroke-linecap="round" fill-rule="evenodd"
stroke="#FF9900" stroke-opacity="0.5" stroke-width="5" fill="#FF9900" fill-
opacity="0.2" class="leaflet-clickable" d="M714 300L709 586L529 591L533
300z"></path></g>
<g><path stroke-linejoin="round" stroke-linecap="round" fill-rule="evenodd"
stroke="#FF9900" stroke-opacity="0.5" stroke-width="5" fill="#FF9900" fill-
opacity="0.2" class="leaflet-clickable" d="M1011 305L1009 585L802 589L797
302z"></path></g>
<g><path stroke-linejoin="round" stroke-linecap="round" fill-rule="evenodd"
stroke="#00FFD5" stroke-opacity="0.5" stroke-width="5" fill="#00FFD5" fill-
opacity="0.2" class="leaflet-clickable" d="M690 444L688 554L544 552L544
433z"></path></g>
<g><path stroke-linejoin="round" stroke-linecap="round" fill-rule="evenodd"
stroke="#FFFFFF" stroke-opacity="0.5" stroke-width="5" fill="#FFFFFF" fill-
opacity="0.2" class="leaflet-clickable" d="M989 321L987 444L816 435L816
320z"></path></g>
</svg><div class="leaflet-draw-guides"></div></div>
Each of these polygons (G's) can be located by XPATH and/or CSS, however, I am encountering NoSuchElementException every time.
This is the code snippet I am executing:
public void dragAndDropPlanos(String nombre, WebElement poligono) {
wait.until(ExpectedConditions.numberOfElementsToBe(By.xpath("//*[contains(text(),'" + nombre + "')]"), 1));
WebElement element = driver.findElement(By.xpath("//*[contains(text(),'" + nombre + "')]"));
js.executeScript("arguments[0].scrollIntoView(true);", element);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
WebElement element1 = driver.findElement(By.xpath("//*[contains(text(),'" + nombre + "')]"));
wait.until(ExpectedConditions.visibilityOf(element1));
// WebElement target = poligono;
wait.until(ExpectedConditions.visibilityOf(poligono));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
WebElement element3 = driver.findElement(By.xpath("//*[contains(text(),'" + nombre + "')]"));
(new Actions(driver)).dragAndDrop(element3, poligono).perform();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
In the above code, I pass a string name as an argument, concatenate it with XPATH to locate the element for dragging, and also pass a webelement representing the polygon where I intend to drop the element. It seems like the SVG may exist in a different iframe, but after switching through iframes, I realized it is only within a div and accessible via xpath.
If anyone could shed some light on this issue, it would be greatly appreciated.
Thank you in advance!