So i have the following HTML Code of a listbox here:
<div role="listbox" aria-expanded="false" class="quantumWizMenuPaperselectEl docssharedWizSelectPaperselectRoot freebirdFormviewerViewItemsSelectSelect freebirdThemedSelectDarkerDisabled" jscontroller="YwHGTd" jsaction="click:cOuCgd(LgbsSe); keydown:I481le; keypress:Kr2w4b; mousedown:UX7yZ(LgbsSe),npT2md(preventDefault=true); mouseup:lbsD7e(LgbsSe); mouseleave:JywGue; touchstart:p6p2H(LgbsSe); touchmove:FwuNnf; touchend:yfqBxc(LgbsSe|preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd(LgbsSe); focus:AHmuwe; blur:O22p3e;b5SvAb:TvD9Pc;" jsshadow="" jsname="W85ice" aria-describedby="i.desc.709120473 i.err.709120473" aria-labelledby="i73">
<div jsname="LgbsSe" role="presentation">
<div class="quantumWizMenuPaperselectOptionList" jsname="d9BH4c" role="presentation">
<div class="quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption isSelected isPlaceholder" jsname="wQNmvb" jsaction="" data-value="" aria-selected="true" role="option" tabindex="0">
<div class="quantumWizMenuPaperselectRipple exportInk" jsname="ksKsZd"></div>
<content class="quantumWizMenuPaperselectContent exportContent">Auswählen</content>
</div>
<div class="quantumWizMenuPaperselectOptionSeparator" role="presentation"></div>
<div class="quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption" jsname="wQNmvb" jsaction="" data-value="140 cm" aria-selected="false" role="option" tabindex="-1">
<div class="quantumWizMenuPaperselectRipple exportInk" jsname="ksKsZd"></div>
<content class="quantumWizMenuPaperselectContent exportContent">140 cm</content>
</div>
<div class="quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption" jsname="wQNmvb" jsaction="" data-value="141 cm" aria-selected="false" role="option" tabindex="-1">
<div class="quantumWizMenuPaperselectRipple exportInk" jsname="ksKsZd"></div>
<content class="quantumWizMenuPaperselectContent exportContent">141 cm</content>
</div>
<div class="quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption" jsname="wQNmvb" jsaction="" data-value="142 cm" aria-selected="false" role="option" tabindex="-1">
<div class="quantumWizMenuPaperselectRipple exportInk" jsname="ksKsZd"></div>
<content class="quantumWizMenuPaperselectContent exportContent">142 cm</content>
</div>
<div class="quantumWizMenuPaperselectOption freebirdThemedSelectOptionDarkerDisabled exportOption" jsname="wQNmvb" jsaction="" data-value="143 cm" aria-selected="false" role="option" tabindex="-1">
<div class="quantumWizMenuPaperselectRipple exportInk" jsname="ksKsZd"></div>
<content class="quantumWizMenuPaperselectContent exportContent">143 cm</content>
</div>
</div>
<div class="quantumWizMenuPaperselectDropDown exportDropDown" role="presentation"></div>
</div>
<div class="exportSelectPopup quantumWizMenuPaperselectPopup" jsaction="click:dPTK6c(wQNmvb); mousedown:uYU8jb(wQNmvb); mouseup:LVEdXd(wQNmvb); mouseover:nfXz1e(wQNmvb); touchstart:Rh2fre(wQNmvb); touchmove:hvFWtf(wQNmvb); touchend:MkF9r(wQNmvb|preventMouseEvents=true)" role="presentation" jsname="V68bde" style="display:none;"></div>
</div>
I am writing an program which has to select an element of this listbox automatically in java (like "140 cm", "141 cm" like you see in the code etc...). I tried to access the listbox itself with the following code:
WebElement checkBox = driver.findElement(By.cssSelector("div[aria-labelledby*=i73]"));
CheckBox.click();
It worked but now i have to select somehow an element of this listbox. I tried it with the 'Select'-Command, which did not work:
Select listbox = new Select(checkBox);
listbox.selectByVisibleText("140 cm");
I also tried it with clicking on the specific div with the '140 cm' text and waiting for its clickability. But I get a timeout exception because it failed to wait for the element to be clickable.
WebElement boxElement = driver.findElement(By.cssSelector("div[data-value*='140']"));
WebDriverWait wait = new WebDriverWait(driver, 10);
boxElement = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[data-value*='140']")));
boxElement.click();
I am desperate and do not know what to do. Can any of you guys help me? I am thankfully for every answer!
greetings
Related
I am trying to get a variable department.id for the selected department when anchor edit or delete is clicked I try with <#assgn departmentId = "${department.id}"> but that return the last id from the table.Since is in the loop I also try with onclick="<#assgn departmentId = "${department.id}">" this also return me last id is there a way to get the current id of the department when is clicked edit or delete with Apache Free Marker
HTML
<tbody>
<#assign count = 1>
<#list departmentsList as department>
<tr>
<td>${count}</td>
<td>${department.name}</td>
<td class="text-right">
<div class="dropdown dropdown-action">
<i class="material-icons">more_vert</i>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#edit_department"><i class="fa fa-pencil m-r-5"></i> Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#delete_department"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
</div>
</div>
</td>
</tr>
<#assign count ++>
</#list>
</tbody>
<tbody>
<#assign count = 1>
<#list departmentsList as department>
<tr>
<td>${count}</td>
<td>${department.name}</td>
<td class="text-right">
<div class="dropdown dropdown-action">
<i class="material-icons">more_vert</i>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#edit_department" onclick="myEditFunction(${department.id})"><i class="fa fa-pencil m-r-5"></i> Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#delete_department" onclick="myDeleteFunction(${department.id})"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
</div>
</div>
</td>
</tr>
<#assign count ++>
</#list>
</tbody>
<script>
function myDeleteFunction(departmentId) {
console.log("deleting department " + departmentId);
}
function myEditFunction(departmentId) {
console.log("editing department " + departmentId);
}
</script>
I am writing selenium scripts for the following code.
<div id="abc" class="ui-selectmanycheckbox ui-widget hpsapf-chechkbox">
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible">
<input id="abc:0" name="abc" type="checkbox" value="0" checked="checked">
</div>
<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active">
<span class="ui-chkbox-icon ui-icon ui-icon-check ui-c"></span>
</div>
</div>
<span class="hpsapf-radio-label">
<label for="abc:0">Herr</label>
</span>
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible">
<input id="abc:1" name="abc" type="checkbox" value="1">
</div>
<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
<span class="ui-chkbox-icon ui-icon ui-icon-blank ui-c"></span>
</div>
</div>
<span class="hpsapf-radio-label">
<label for="abc:1">Frau</label>
</span>
</div>
These are the checkbox like the following.The number of the checkboxes are changed as per database values.
In my code i am first checking whether the "Frau" check box is selected or not. so i tried following snippet.
WebElement mainElement= driver.findElement(By.id("abc"));
WebElement label=mainElement.findElement(By.xpath(".//label[contains(#for,'abc')][text() = 'Frau']"));
WebElement parent = label.findElement(By.xpath(".."));
WebElement div = parent.findElement(By.xpath("preceding-sibling::::div"));
WebElement checkBox = div.findElement(By.className("ui-chkbox-box"));
String css = checkBox.getAttribute("class");
if(css.contains("ui-state-active")) {
return "checked";
}
else
{
return "unchecked";
}
But when i tried to execute this script. WebElement div = parent.findElement(By.xpath("preceding-sibling::::div")); gives me the first div tag and not the preceding one. I want a preceding sibling.
Use :: and index, not ::::
WebElement div = parent.findElement(By.xpath("preceding-sibling::div[1]"));
I'm new to Selenium webdriver. Can someone help me how to get the span element in table row
<span class="small-info" title="zim.lu#en.com , stins.gib#en.com "> zim.lu#en.com , stin.gib#en.com </span>
in below Table
<table class="k-selectable" role="grid" data-role="selectable">
<colgroup>
<tbody role="rowgroup">
<tr class="k-state-selected" role="row" data-uid="39c56242-2108-4b6d-b80f-1e2f266cd02f" aria-selected="true">
<td role="gridcell">
<div class="left-info">
<div id="item193689" class="inbox-info">
<div class="left-inboxInfo">
<h2 class="SubjecthOverflow">
<span class="small-info" title="zim.lu#en.com , stins.gib#en.com "> zim.lu#en.com , stin.gib#en.com </span>
<div id="policydiv193689">
</div>
<div class="right-inboxInfo">
</div>
</td>
</tr>
<tr class="k-alt" role="row" data-uid="32a122c7-2e7b-4a28-bb77-5fde6679e6ec">
<td role="gridcell">
<div class="left-info">
<div id="item202147" class="inbox-info">
<div class="left-inboxInfo">
<h2 class="SubjecthOverflow">
<span class="small-info" title="kev.kind#en.com , vin.kami#en.com "> ke.kin#en.com , vi.kami#en.com </span>
<div id="policydiv202147">
</div>
<div class="right-inboxInfo">
</div>
</td>
</tr>
</tbody>
</table>
I tried this code
WebElement table_element = dr.findElement(By.className("k-selectable"));
List<WebElement>tr_collection=table_element.findElements(By.xpath("//span[#class='small-info']"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
Output not showing
List<WebElement>tr_collection=dr.findElements(By.xpath("//span[#class='small-info']"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
You can find the element by using xpath or css selector
Try this below code in your list
dr.findElements(By.xpath("//*[#role='grid']/colgroup/tbody/tr/td/div/div/div/h2/span"));
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.
I am new with using Jsoup and i have a problem to get the text value from div with class name text as a string.
This is the string that a want to scrap.
<body>
<div class="details ">
<div class="title turquoise2">
AAC-Olympia
</div>
<div class="subhead turquoise2">
Correspondentie-adres:
</div>
<div class="text">
Rijdt 37
<br /> 6631AP HORSSEN
<br /> 0487-541339
</div>
<div class="subhead turquoise2">
Accommodatie:
</div>
<div class="text">
Sportpark De Polenkamp
<br /> Bredestraat 3
<br /> 6631BC HORSSEN
<br /> 0487-541339
</div>
<div class="subhead turquoise2">
Opgericht:
</div>
<div class="text">
01-07-2011
</div>
<div class="subhead turquoise2">
Tenue:
</div>
<div class="text">
Shirt: Wit
<br /> Broek: Zwart
<br /> Kousen: Zwart
</div>
<div class="subhead turquoise2">
Regio:
</div>
<div class="text">
Veldregio: Regio 4 veld
<br /> Zaalregio:
</div>
<div class="subhead turquoise2">
Info:
</div>
<div class="text">
Relatienummer: NXTG36Z
<br /> Email:
janberg37#Caiway.nl
<br /> Website:
http://www.aac-olympia.nl
<br /> District: Oost
</div>
<div class="subhead turquoise2">
Klasse(s):
</div>
<div class="text">
Klasse za:
<br /> Klasse zon: 5e klasse
<br /> Klasse zaal:
<br /> Junioren: Nee
<br /> Pupillen: Nee
<br /> Vrouwen: Nee
<br /> G-Voetbal: Nee
</div>
<div class="text">
Overzicht indeling district Oost
</div>
</div>
<div class="details details-functionaris">
<div class="title turquoise2">
AAC-Olympia
</div>
<div class="voorzitter">
</div>
<div class="secretaris">
</div>
<div class="penningmeester">
</div>
<div class="functionarissen">
</div>
</div>
</body>
I want to get from second div with class name text following information separate, i tried following code but gives me empty string,
Element Adres = finalDocument.getElementsByClass("text").get(1);
String AllTextValue = Adres.text();//This give me all information from the div
But i want all 4 text value apart,
String firstText = For this one i have no ieee what i need to do
String SecondText = Adres.getElementsByTag("br").get(0).text();//Returns Empty value
String ThirdText = Adres.getElementsByTag("br").get(1).text();//Returns Empty value
String FourthText = Adres.getElementsByTag("br").get(2).text();//returns Empty value
Can somebody help me.
Thank i lot.
Elements implements the List interface so just use:
Elements Email = finalDocument.getElementsByTag("a");
String emailAddress = Email.get(0).text();
Naming the Elements object Email is slightly misleading. I would recommend the following refactored code:
Elements anchors = finalDocument.getElementsByTag("a");
String email = anchors.get(0).text();