List<WebElement>.get(i).click picking up random elements - java

I have a list of images and each need to be clicked.
Below is the HTML
<div id="VELayerListDiv">
<div id="msftve_1002">
<a id="msftve_1002_200000_10000" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: -17px; top: 450px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1002_200000_10000",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1002_200000_10000",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_50-499_U2.png"/>
</div>
</div>
</a>
</div>
<div id="msftve_1003">
<a id="msftve_1003_200003_10003" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: 278.5px; top: 363.5px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1003_200003_10003",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1003_200003_10003",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_2-49_U2.png"/>
</div>
</div>
</a>
<a id="msftve_1003_200004_10004" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: 277.5px; top: 362.5px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1003_200004_10004",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1003_200004_10004",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_2-49_U2.png"/>
</div>
</div>
</a>
</div>
I have written the following code:
List<WebElement> pins = driver.findElements(By.xpath("//*[#id='VELayerListDiv']/div/a/div/div/img")));
System.out.println("Total Pins :"+pins.size());
for(int x=0;x<pins.size();x++)
{
pins.get(x).click();
}
The above code clicks the pins randomly. It is not clicking all the Pins uniquely (i.e all imgs). I get click on img1,img2,img1,img3,img1
I am not sure what is wrong as I get all the img's in the list (as pins.size() is correct). But the click does not click every img uniquely.
It is something to do with img tag not having any unique identifier.

Related

Not able to Intract with iframe

ImageHow can I handle this window which popup when saving a record I tried Actions class, robot class but nothing seems to work.
<div tabindex="-1" role="dialog" class="ui-dialog ui-corner-all ui-widget
ui-widget-content ui-front critical-dialog ui-dialog-buttons" aria-
describedby="ui-id-7" aria-labelledby="ui-id-8" style="height: auto;
width:
300px; top: 302.005px; left: 611.48px;"><div class="ui-dialog-titlebar ui-
corner-all ui-widget-header ui-helper-clearfix"><span id="ui-id-8"
class="ui-dialog-title"> </span><button type="button" class="ui-
dialog-titlebar-close fa fa-close"></button></div><div id="ui-id-7"
class="ui-dialog-content ui-widget-content" style="z-index: 3000000;
width: auto; min-height: 28.86px; max-height: none; height: auto;"><div
class="title"></div><div class="message">Search updated successfully!
</div></div><div class="ui-dialog-buttonpane ui-widget-content ui-helper-
clearfix"><div class="ui-dialog-buttonset"><button
type="button">OK</button></div></div></div>
and
<iframe tabindex="-1" aria-hidden="true" role="presentation"
title="Intentionally blank" name="lpSS_38260369681" id="lpSS_38260369681"
src="https://lpcdn.lpsnmedia.net/le_secure_storage/3.7.0.1-
release_442/storage.secure.min.html?
loc=https%3A%2F%2Fqa.criticalmention.com&site=10551349&env=prod"
style="width: 0px; height: 0px; position: absolute; top: -1000px; left:
-1000px; display: none;"></iframe>
Before interacting with an element inside of an iframe, you need to switch to it:
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Intentionally blank']")));

How to read the content of Tableue graphs in Selenium WebDriver?

The graph on the website looks like :
enter image description here
I need to read the pop up data when i hover on the graph. I cannot do inspect element on the pop up data.
In HTML i can see below code:
<div id="view5561218686836924094_14132909152772909395" class="tab-tvView tvimagesNS" style="background-color: rgb(255, 255, 255); left: 20px; top: 25px; width: 192px; height: 230px;">
<div class="tvScrollContainer tvmodeRectSelect" style="cursor: pointer; left: 0px; top: 0px; width: 192px; height: 230px;">
<div class="tvBackgroundContainer" style="background-color: rgb(255, 255, 255);"/>
<div class="tvimagesContainer" style="width: 192px; height: 230px;">
<canvas class="tabCanvas tab-widget" width="192" height="230" style="width: 192px; height: 230px;"/>
<canvas class="tabCanvas tab-widget" style="position: absolute; left: 0px; top: 0px; width: 192px; height: 230px;" width="192" height="230"/>
</div>
<div class="tvdrag" style="display: none;">
<div class="tvdrag_image" style="display: none;"/>
<div class="tvdrag_mask" style="display: none;"/>
</div>
<div class="tvdrag" style="display: none;"/>
</div>
Please help. Thank you.

how to submit only checked checkboxes

I want to add a "submit" button that submits only the checked checkboxes.
I don't know how to pass only the checked ones to the server.
thanks.
The Button:
<a:commandButton id="saveAllBtn" value="Submit All" style="width: 60px; cursor:pointer" action="#{urlAction.saveAll()}"
reRender="qualificationForm,messages"
disabled="#{urls.rowCount==0}" requestDelay="100"
onclick=" disableOperations();beforeRedirect();"
onfocus="highlightButton(this);" onblur="unhighlightButton(this);"
actionListener="#{growlBean.save}">
</a:commandButton>
The checkboxes:
<div id="urlsContainer" class="list-group"
style='width: 350px; word-wrap: break-word; margin-top: 10px'>
<a:repeat value="#{urlAction.urlsIndexList}" var="_urlIndex">
<a href='#' class='list-group-item'
style='float: left; width: 350px; height: 50px;'>
<input type='checkbox' class="urlCheckBox" name='checkbox-1'
style='margin-left: 15px; float: left;'>
<span style='margin-left: 10px; font-size: 12px; float: left;
word-break: break-all; width: 300px;'
onclick='showFraim("#{_urlIndex}")'>#{urlAction.getUrl(_urlIndex)}
</span>
</input>
</a>
</a:repeat>
</div>
I have all the URLs in a list named "urls" in a java class named urlAction.
Example:
[x] www.google.com
[ ] www.yahoo.com
[x] www.nytimes.com
If I checked the first and third what would be submitted are:
www.google.com
www.nytimes.com
By default only the checked checkboxes are sent. You do need to give the checkboxes a value, for instance value="1".
<input type='checkbox' class="urlCheckBox" name='checkbox-1'
style='margin-left: 15px; float: left;' value="1">

Dynamically displaying divison from data being fetched from database

I was tring to make a question answer forum in which each question being displayed is having three divisons : Answers Count,View count,Question.So for achieving this I do something like this :
<div id="container">
<div id="a">
<p align="center">0</p>
<p align="center">Answers</p>
</div>
<div id="b-wrapper">
<div id="b">
<p align="center">0</p>
<p align="center">Views</p>
</div>
</div>
<div id="c-wrapper">
<div id="c">
<p align="center">Question</p>
<p align="right">Asked By Micheal</p>
</div>
</div>
<br style="clear: both;">
</div>
In css i did :
#container {
width: 800px;
}
#a, #b-wrapper, #c-wrapper {
float: left;
}
#a {
width: 10%;
background-color: #0ff;
}
#b-wrapper {
width: 10%;
}
#b {
margin-left: 20px;
background-color: #0f0;
}
#c-wrapper {
width: 60%;
}
#c {
margin-left: 20px;
background-color: #EEEEEE;
}
Now I am facing two problems.
The divison for Answer is getting a bit bigger in height.How to manage it.
I am fetching questions from database Like :
while(rs.next){
String myid=rs.getString("ID");
//display here all three divisons where rs is ResultSet
}
So here problem is that i want to assign this myid to each of the divison And on click of any divison move to second.jsp.
Please help to solve these problems.

How to select an item in the drop down using webdriver (with or without using xpath)

I have an issue while selecting a dropdown which is also an input field using selenium webdriver and java.
1) After the pop up appears, I will have to click the drop down and select a field and tab to the next drop down and select one more drop down and select a field .
2) These drop downs also act as input fields, so I used the input id for my xpath and it does type in the box instead of selecting it. Now I don't want to go that route.Instead want to select from the dropdown itself.
Here is the HTML of the pop up. ANy ideas??
Here is what I have written:
WebElement orgUnitText = driver.findElement(By.xpath("//input[#id='textfield-1137- inputEl']"));
orgUnitText.sendKeys("HRD");
logger.info("entered OrgUnitText");
WebElement orgUnitAbb = driver.findElement(By.xpath("//input[#id='textfield-1138- inputEl']"));
orgUnitAbb.sendKeys("HRD");
logger.info("entered OrgUnit abbreviation");
Thread.sleep(15000);
List<WebElement> options = driver.findElements(By.id("combobox-1140-inputEl"));
options.get(0).sendKeys("HR_ADMINS");
List<WebElement> options2 = driver.findElements(By.id("combobox-1141-inputEl"));
options2.get(0).sendKeys("HR_USERS");
WebElement textArea = driver.findElement(By.id("textareafield-1143-inputEl"));
textArea.sendKeys("HRD");
WebElement saveButton = driver.findElement(By.xpath("//a[#id='button-1146-btnEl']"));
saveButton.click();
logger.info("entered OrgUnit description");
</div>
<div id="orgunitpanel-1134-body" class="x-window-body x-window-body-default x-layout-fit x-closable x-window-body-closable x-window-body-default-closable x-window-body-default x-window-body-default-closable" style="background: none repeat scroll 0% 0% white; width: 690px; left: 0px; top: 20px; height: 178px;">
<div id="form-1135" class="x-panel x-fit-item x-window-item x-panel-default" style="padding: 5px; margin: 0px; width: 688px; height: 176px;">
<div id="form-1135-body" class="x-panel-body x-panel-body-default x-panel-body-default x-docked-noborder-top x-docked-noborder-right x-docked-noborder-bottom x-docked-noborder-left" style="width: 678px; left: 0px; top: 0px; height: 166px;">
<span id="form-1135-outerCt" style="display: table; width: 100%; table-layout: fixed;">
</div>
</div>
</div>
<div id="toolbar-1145" class="x-toolbar x-docked x-toolbar-footer x-docked-bottom x-toolbar-docked-bottom x-toolbar-footer-docked-bottom x-box-layout-ct" style="width: 690px; right: auto; left: 4px; top: 202px;">
<div id="toolbar-1145-innerCt" class="x-box-inner " role="presentation" style="width: 684px; height: 22px;">
<div id="toolbar-1145-targetEl" class="x-box-target" style="width: 684px;">
</div>
</div>
</div>
<div id="boundlist-1150" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-resizable x-boundlist-resizable x-boundlist-default-resizable" tabindex="-1" style="right: auto; left: 1101px; top: 407px; width: 176px; z-index: 29001; height: auto; display: none;">
<div id="boundlist-1150-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<div id="boundlist-1150-southeast-handle" class="x-resizable-handle x-resizable-handle-southeast x-boundlist-handle x-boundlist-handle-southeast x-boundlist-handle-southeast-br x-unselectable" unselectable="on"></div>
</div>
<div id="ext-gen1284" class="x-mask" style="z-index: 29001; width: 176px; height: 133px; right: auto; left: 1101px; top: 407px; visibility: hidden;"></div>
<div id="loadmask-1151" class="x-mask-msg x-layer x-mask-msg-default" style="right: auto; left: 1143px; top: 457px; z-index: 29003; display: none;">
<div id="loadmask-1151-msgEl" class=" x-mask-msg-inner">
</div>
</body>
</html>
Just use class Select that wraps WebElement and contains functions that allows to select option by value, visible text, get list of options and so on.

Categories

Resources