How to verify the checkbox on a section, maximum 10, 2 in a row, and the checkbox is checked?
To verify checkbox is checked
Boolean isCheckboxChecked =
driver.findElement(By.xpath("//*[contains(#class, 'checkboxSection')]//input[#type='checkbox']")).isSelected();
To verify max checkbox on that section is 10
Boolean isCheckboxMaxTen =
driver.findElements(By.xpath("//*[contains(#class, 'checkboxSection')]//input[#type='checkbox']")).size() <= 10;
To verify max 2 checkbox in a row
Any idea how to verify max 2 checkbox in a row
if ((isCheckboxChecked == true) && (isCheckboxMaxTen == true) && (isCheckboxTwoInARow == true)){
// Pass
}
else
{
// Fail
}
Added html code
<form name="formApp" method="post" action="/apps/GeneralManager">
<div class="USK_A">
<img class="BOL_B" alt="" src="http://apps.com"/>
<div class="MOV_HOL_A">
<p class="bold">
<ul class="form_movie">
<li>
<input type="checkbox" checked="checked" value="3000000190795" name="point_id"/>
Movie_A
</li>
</ul>
<p class="mv5">
</div>
</div>
</form>
Related
I have a dropdown menu with 2 options(option1 and option2).I want to get the NAME of the first option and compare with a string.
I tried something like this but not work for me:
The drop down menu has two items:
-first(default) is "simplex"
-second is "duplex"
The HTML drop down is:
<div class="fieldHelp " id="fieldHelp8352">
<script></script>
<select id="8352" class="lazy-droplist" aria-labelledby="8351" name="pMode:value" style="display: none;">
<option selected value="0">simplex</option>
<option value="1">duplex</option>
</select>
<label id="extendClickArea_8352" style="height:40px; width:100%; position: relative;" class="lazy-droplist">
<span class="ui-selectmenu-button lazy-droplist" tabindex="0" id="8352-button" role="combobox" aria-expanded="false" aria- autocomplete="list" aria-owns="8352-menu" aria-haspopup="true" style="width: 100%;" aria-activedescendant="ui-id-1003" aria- labelledby="ui-id-1003" aria-disabled="false" data-modalfocus="">
<span class="ui-icon ui-icon-triangle-1-s"></span>
<span class="ui-selectmenu-text">simplex</span>
</span>
</label>
<div id="bs-help-modal-sm-8352" style="display: none;" class="bs-help-modal-sm-8352 ui-draggable" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-content"><div class="modal-header ui-draggable-handle">
<button type="button" class="close" aria-label="Close" onclick="closeHelpPopup(event, $('#bs-help-modal-sm-8352'));">
<span aria-hidden="true">×</span></button>
.....
.....
</div>
<script>
$('#bs-help-modal-sm-8352').draggable({ handle: '.modal-header' });
</script>
</div>
Noticed that the code is somehow grayout,inactive but when I tried to extract test "simplex" ,not said that the menu is hidden or something...
Java code is:
Select select = new Select(driver.findElement(By.name("simplex")));
WebElement option = select.getFirstSelectedOption();
String defaultItem = option.getText();
System.out.println(defaultItem);->this variable is empty :(
if (defaultItem == "simplex") {
System.out.println("Is Simplex");
} else {
System.out.println("Is Duplex");
Where I do something wrong because defaultItem is empty...
Thks
In your case, I cant see name attribute with "simplex" anywhere in the code provided by you. Also, a problem I can see in HTML code is it does not have any value for a selected attribute that's why you getting the empty value:
<option selected="" value="0">simplex</option>
Try below method:
Select select = new Select(driver.findElement(By.id("8352")));
List<WebElement> options = select.getOptions();
int optionssize= options.size();
for(int i=0;i<optionssize;i++)
{
if(options.get(i).getText().equals("Simplex"))
{
System.out.println("Is Simplex available at"+i);
break;
}
}
Solved.
The solution was:
String Text = driver.findElement(By.id("the_direct_path_to_this_span_<span class="ui-selectmenu-text">simplex</span>")).getText();
if(text.equals("Simplex"))
{
System.out.println("Is Simplex");
} else {
System.out.println("Is NOT Simplex");
}
I have a button with drop down item,
if i click the button it's open the list and choose the item
below is the html
<button id="btn-append-to-body" class="btn btn-primary mobile-quick-button dropdown-toggle" type="button" uib-dropdown-toggle="" aria-haspopup="true" aria-expanded="false">
<div class="clearfix">
<span class="pull-left text-left ng-binding" tabindex="0"> Select one </span>
<span class="pull-right text-right ng-binding">
</div>
</button>
<ul class="uib-dropdown-menu dropdown-menu" role="menu" aria-labelledby="btn-append-to-body">
<!-- ngRepeat: option in dropOptions -->
<li id="quickOption" class="ng-scope" role="presentation" name="quickOption" ng-repeat="option in dropOptions" ng-click="selectOption(option)" required="" tabindex="0" style="">
<a href="">
<div class="clearfix">
<span class="pull-left ng-binding">frame number</span>
</div>
</a>
</li>
<!-- end ngRepeat: option in dropOptions -->
<li id="quickOption" class="ng-scope" role="presentation" name="quickOption" ng-repeat="option in dropOptions" ng-click="selectOption(option)" required="" tabindex="0">
<a href="">
<div class="clearfix">
<span class="pull-left ng-binding">serial number</span>
</div>
</a>
</li>
</ul>
I want to choose any one of the item from this list,
public void lookupSearch (String item){
driver.findElement(By.xpath("//*[#id='btn-append-to-body']")).click();
//then i choose/click the parameter item (i.e frame number or serial number)
}
passing the item as parameter
please guide me how should i choose the item
To click on the button with drop down item and choose any one of the item from this list you can use the following code block :
public void lookupSearch (String item)
{
driver.findElement(By.xpath("//button[#id='btn-append-to-body']/div/span[contains(.,'Select one')]")).click();
WebDriverWait wait4elements = new WebDriverWait(driver, 10);
List<WebElement> myElements = wait4elements.until(ExpectedConditions.numberOfElementsToBe(By.xpath("//ul[#class='uib-dropdown-menu dropdown-menu']/li/a/div/span"), 2));
for(WebElement elem:myElements)
if(elem.getAttribute("innerHTML").contains(item))
{
elem.click();
break;
}
System.out.println("Element with text as "+ item +" is selected");
}
below is the answer from ul find the Li count, then getting each li text and compare with item string
WebElement uList = driver.findElement(By.xpath("//*[#id='quick-search-dropdown']/ul"));
List<WebElement> listCount = uList.findElements(By.tagName("li"));
for (int i = 1; i <= listCount.size(); i++) {
WebElement lookupItem = driver.findElement(By.xpath("(//li[#id='quickOption']/a/div/span[1])[" + i + "]"));
String lookupItemValue = lookupItem.getText();
if (lookupItemValue.equalsIgnoreCase(Item)) {
lookupItem.click();
}
}
I am trying to find button add to cart is present or not using loop from all item box from following code
<div class="page-body">
<div class="product-selectors">
<div class="product-filters-wrapper">
<div class="product-grid">
<div class="item-box">
<div class="item-box">
<div class="item-box">
<div class="item-box">
</div>
in each item box folowing code
<div class="item-box">
<div class="product-item" data-productid="20">
<div class="picture">
<div class="details">
<h2 class="product-title">
<div class="product-rating-box" title="1 review(s)">
<div class="description"> 12x optical zoom; SuperRange Optical Image Stabilizer </div>
<div class="add-info">
<div class="prices">
<div class="buttons">
<input class="button-2 product-box-add-to-cart-button" type="button" onclick="AjaxCart.addproducttocart_catalog('/addproducttocart/catalog/20/1/1 ');return false;" value="Add to cart">
</div>
</div>
</div>
</div>
</div>
I need to find that all itembox have add to cart button present or not using loop. if anyone can help please
I suggest to avoid looping if not necessary. You do not need to do the loop to find out unless there is an explicit need of doing so. You can find the count of Add to cart button and compare with a known value
By byCss = By.cssSelector(".item-box>div input[value='Add to cart']");
int cartCount = driver.findElements(byCss).size();
if (cartCount != 4){
//fail the test
}
If you exactly one to looping and check if the input button exist or not.
By itemBoxes = By.className("item-box");
By button = By.cssSelector("[type='button'][value='Add to cart']");
List<WebElement> webElementList = driver.findElements(itemBoxes);
for (WebElement element: webElementList){
//simply taking size if exist it will return 1
if (element.findElements(button).size() != 1){
//fail
}
}
you can use searching by xpath inside of the loop.
Something like
".//input[#value='Add to cart'][1]"
".//input[#value='Add to cart'][2]"
".//input[#value='Add to cart'][3]"
etc
not sure that this xpath is correct, but generally it will work for you, bro.
Or something like this:
string xpath=".//input[#value='Add to cart']";
var AddToCartBtnsList = driver.findElements(By.Xpath(xpath));
foreach(IWebElement button in AddToCartBtnsList )
{
button.click();
}
<html>
<head>
<title>HTML Checkbox</title>
</head>
<body>
enter code here
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="fruits.php" method="POST">
<input type="checkbox" name="fruit[]" value="orange"> Orange
<input type="checkbox" name="fruit[]" value="apple"> Apple
<input type="checkbox" name="fruit[]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[]" value="banana"> Banana
<input type="checkbox" name="fruit[]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
Anyone can give me an idea how to validate this checkobox array.
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array();
foreach($chkbox as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
}
this is part of my code. I want to limit the checked checkbox to 5. Thanks. I need it badly :|
Try this. You can limit in javascript itself. So you can limit user in client side no need to go server side. It will limit you for 4 items. You can change the number in the script to increase the value
<script type="text/javascript">
function validateitem(){
var items = document.forms['fruitcheckbox'];
var inc = 0;
var i;
for (i = 0; i < items.length; i++) {
if (items[i].checked) {
inc++;
}
}
if(inc == 0) {
document.getElementById("limitmsg").innerHTML = 'Select atleast 1 item.';
return false;
} else if(inc>4){
document.getElementById("limitmsg").innerHTML = 'You can select only 4 items.';
return false;
}
}
</script>
<h2>Pick your most favorite fruits:</h2>
<form name="fruitcheckbox" action="fruits.php" method="POST"
onsubmit="return validateitem();">
<input type="checkbox" name="fruit[]" value="orange"> Orange <input
type="checkbox" name="fruit[]" value="apple"> Apple <input
type="checkbox" name="fruit[]" value="grapefruit"> Grapefruit <input
type="checkbox" name="fruit[]" value="banana"> Banana <input
type="checkbox" name="fruit[]" value="watermelon"> Watermelon <br> <span
style="color: red" id="limitmsg"></span><input type="submit"
value="Save" name="btnsave">
</form>
Do you need something like this?
if (isset($_POST['btnsave'])) {
$fruits = $_POST['fruit'];
$count = count($fruits);
if ($count > 5) {
// Error; Only 5 checks allowed
} else {
// Save the data
}
}
When you submit fields with brackets like in your example. name="fruit[]" it will be an array when it is received in the backend in php.
You could then just use this:
if(isset($_POST['fruit']) && count($_POST['fruit']) > 5) {
// add your error message
} else {
// Everything is fine as long as you dont have to select atleast one of them
}
If my understanding is not wrong you have more then 5 checkboxes and you want user to restrict to check only 5 checkboxes.
If this is the case then below code might help you.
$("input[name='fruit[]']").change(function(e) {
if($('input[name="fruit[]"]:checked').length==5) {
$("input[name='fruit[]']:not(:checked)").attr("disabled", true);
} else {
$("input[name='fruit[]']:not(:checked)").attr("disabled", false);
}
});
Above code will allow you to check only 5 check boxes, whenever user check the 5th checkbox it will disable the remaining unchecked checkboxes. whenever user uncheck any of the 5 checkboxes then it will enable all the checkboxes.
I want to use pagination and I did it but I am not getting that part I want. I want through some solution but still not getting.
What am I doing is:
query part in model:
public static Page<User> page(int page, int pageSize, String sortBy, String order, String filter) {
return find.where()
.ilike("name", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.findPagingList(pageSize)
.getPage(page);
}
view part:
#(currentPage: com.avaje.ebean.Page[User], currentSortBy: String, currentOrder: String, currentFilter: String,ud: String)
#****************************************
* Helper generating navigation links *
****************************************#
#link(newPage:Int, newSortBy:String) = #{
var sortBy = currentSortBy
var order = currentOrder
if(newSortBy != null) {
sortBy = newSortBy
if(currentSortBy == newSortBy) {
if(currentOrder == "asc") {
order = "desc"
} else {
order = "asc"
}
} else {
order = "asc"
}
}
// Generate the link
routes.paging.pag(newPage, sortBy, order, currentFilter)
}
#header(key:String, title:String) = {
<a class="#key.replace(".","_") header #if(currentSortBy == key) #{if(currentOrder == "asc") "headerSortDown" else "headerSortUp"}" href="#link(0,key)">#title</a>
}
#main("welcome to EXTR ") {
<div class="container-narrow">
<div class="masthead">
<ul class="nav nav-pills pull-right">
<li><a href="#routes.paging.extrad(ud)" >Extr resume</a></li>
<li>Logout</li>
</ul>
<h3 class="muted">
welcome admin</b>
</h3>
</div>
<hr><div align="center">
<h1> #currentPage.getTotalRowCount() user found</h1>
#if(currentPage.getTotalRowCount == 0) {
<div class="well">
<em>Nothing to display</em>
</div>
} else {
<table border="1" >
<tr>
<th>#header("name","name")</th>
<th>#header("email","email")</th>
<th>#header("","")</th>
</tr>
<tbody>
#for(user <- currentPage.getList) {
<tr>
<td>#user.name</td>
<td>
#user.getEmail()
</td>
<td>delete</td>
</tr>}
</tbody>
</table>
<div id="pagination" class="pagination">
<ul>
#if(currentPage.hasPrev) {
<li class="prev">
← Previous
</li>
} else {
<li class="prev disabled">
<a>← Previous</a>
</li>
}
#for(i <- 0 until currentPage.getTotalPageCount()){
<li>#(i+1)</li>
}
#if(currentPage.hasNext) {
<li class="next">
Next →
</li>
} else {
<li class="next disabled">
<a>Next →</a>
</li>
}
</ul>
</div>
}
</div>
</div>
}
and what am I getting is:
but what I want is
at a time I want to show to 5 pages and when click on 5th page it again get to 5-10 pages. But my pagination is getting all pages at a time.
I want the numbers to be displayed in this format..
1 2 3 4 5 ^
where if I press 5, then it should display from 5 to 10
5 6 7 8 9 10
till the max records are available. I just want to know a how to do this for displaying numbers.
give me some idea to do this.