I want to check/uncheck all checkboxes present in page.
Code snippet is as following:-
#Test
public void checkBoxAll() {
List<WebElement> checkBoxList=driver.findElements(By.cssSelector("input [type='checkbox']"));
for(WebElement checkBox:checkBoxList)
{
checkBox.click();
}
List<WebElement> unCheckedBoxList=driver.findElements(By.cssSelector("input:not(:checked)[type='checkbox']"));
if(!CollectionUtils.isEmpty(unCheckedBoxList))
Assert.fail();
}
First I find out all check boxes using ("input [type='checkbox']").Then click them in loop and then find all check boxes which are checked(for test case to be executed successfully there should be none).
I tried some approaches from google,but ain't working for me.Please tell me what I am doing wrong being a novice
Don't know what was problem in what I was doing earlier or the solution proposed above,but both didn't work.I tried out different things and below is the working solution.id='first' is id of div under which all checkboxes are placed.
#Test
public void CheckBoxAll() {
String cssSelectorForNotCheck=("[id='first'] input[type='checkbox']:not(:checked)");
List<WebElement> checkBoxList=driver.findElements(By.cssSelector(cssSelectorForNotCheck));
for(WebElement checkBox:checkBoxList)
{
checkBox.click();
}
checkBoxList=driver.findElements(By.cssSelector(cssSelectorForNotCheck));
if(!checkBoxList.isEmpty()) {
Assert.fail();
}
A solution is:
// Find all checked checkboxes with xpath
List<WebElement> checkBoxList=driver.findElements(By.xpath("//input[#type='checkbox' and #checked='checked']"));
for(WebElement checkBox:checkBoxList)
{
checkBox.click();
}
// Assert if any checkbox left checked
List<WebElement> allCheckedBoxList=driver.findElements(By.xpath("//input[#type='checkbox' and #checked='checked']"));
if(!allCheckedBoxList.isEmpty()) {
Assert.fail();
}
Update
If you need to look for unchecked checkboxes use following xpath instead:
//input[#type='checkbox' and not(#checked='checked')]
Related
I have a comboBox in XPages which is showing an hierarcal list of categories and values populates as a vector in SSJS.
I now want to apply a styleheet (bold) to the categories (i.e on only the categories of the generated option tags)
please note that I do not need a lesson in how stylesheets work. I need to know how to add a class or style to the categories in the outputted options tags
how can I do that?
thanks
Thomas
UPDATED MY QUESTION WITH A WORKING CLASS
Mimics a categorized view with 3 columns in a comboBox, category, label and value
public class Utils {
public static List<SelectItem> getGroupedComboboxOptions() {
try {
Database db = ExtLibUtil.getCurrentDatabase();
View vv = db.getView("ProdukterByCat");
Vector v = vv.getColumnValues(0);
List<SelectItem> groupedOptions = new ArrayList<SelectItem>();
SelectItemGroup group;
for (int i = 0; i < v.size(); i++) {
List<SelectItem> options = new ArrayList<SelectItem>();
group = new SelectItemGroup(v.get(i).toString());
ViewEntryCollection nvec = vv.getAllEntriesByKey(v.get(i), true);
ViewEntry entry = nvec.getFirstEntry();
while (entry != null) {
SelectItem option = new SelectItem(entry.getColumnValues().get(2).toString(),entry.getColumnValues().get(1).toString());
options.add(option);
entry = nvec.getNextEntry(entry);
}
group.setSelectItems(options.toArray(new SelectItem[options.size()]));
groupedOptions.add(group);
}
return groupedOptions;
} catch (NotesException e) {
e.printStackTrace();
}
return null;
}
}
A combobox in XPages is rendered using a HTML select tag. If you organise the options in optgroup's (see also Populating selectItems of the combobox (label, value) using a managed bean) you get some default styling out of the box. Example here.
You can even apply additional styling on them with standard CSS by targeting the optgroup. But support for that is limited: it doesn't work on an iPad for example.
If you want more control on how your dropdowns look, I'd suggest to use a plugin like Select2.
I have a table component in my form with lots of values. I want a pop up on clicking on each cell in the table to show some information. I wrote a code for that :
dataTable.addPointerPressedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Label c = (Label) dataTable.getClosestComponentTo(evt.getX(), evt.getY());
Dialog.show("Artifact", information, "Ok", null);
}
});
This method only works for last row and last column only and also not picking the right cell (closest cell). What I want is to pick the right cell on clicking in the table. What are the alternatives for doing this ?
I tried another way to do so. Code is
#Override
public void addPointerPressedListener(ActionListener l) {
l = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Label c = (Label) getClosestComponentTo(evt.getX(), evt.getY());
Dialog.show("Popup", c.getText(), "Ok", null);
}
};
super.addPointerPressedListener(l);
}
Both way I am getting problem. Its working on outer cells and at specific points only.
The table is a Container in which each cell is a component in its own right. To track an individual cell you can override the createCell method in table and track the component returned from there.
My question is simple- Using Selenium.Can anyone help me on this.I am using selenium in java.The webpage contain table with 5 columns.In the second column Hyperlinks lists are there.I would like to click each and every link in the second column one by one and check some criteria.
Please do the needful.Thanks in Advance.
=================================================================================
This is my Code Part:
WebElement table = d1.findElement(By.xpath("//*[#id='search_results']/table"));
// Now get all the TR elements from the table
List<WebElement> allRows = table.findElements(By.tagName("tr"));
//WebElement cell1 =allRows.get(1);
// System.out.println("Table"+ allRows.get(1).getText());
//System.out.println(allRows.size());
// And iterate over them, getting the cells
for (WebElement row : allRows) {
List<WebElement> cells = row.findElements(By.tagName("td"));
for (WebElement cell : cells) {
String s = cell.getText();
==================================================================
This code is retrieving all table data's.I need to click each and everylink in the second column values(Hyperlinks) one by one and check some criteria.
=================================================================
It is showing "WebElements" cannot be a resolved type.This is my full code
public class Reading {
public static void main(String[] args) throws InvalidFormatException, IOException, InterruptedException
{
WebDriver d1= new FirefoxDriver();
d1.get("https://fusion.paypal.com/fusionportal/");
WebElement ds = d1.findElement(By.xpath("//*[#id='ext-gen176']/ul/li/a"));
ds.click();
WebElement dt = d1.findElement(By.xpath("//*[#id='ext-gen178_startDate']"));
dt.sendKeys("20/11/2013");
WebElement sc = d1.findElement(By.xpath("//*[#id='searchDeploys']/tbody/tr[2]/td[2]"));
sc.click();
Thread.sleep(2000);
//WebElement table_element = d1.findElement(By.xpath("//*[#id='ext-gen236']"));
//List<WebElement> tr=table_element.findElements(By.xpath("//*[#id='ext-gen236']"));
WebElements links = d1.findElement(By.xpath("//*[#id='ext-gen238']/div[1]/table/tbody/tr/td[2]/div"));
for (WebElement link : links) {
link.click();
}
}
}
Hard to know without seeing the HTML as well, but assuming it's a regular table from the rest of your code, try something like
List<WebElement> links = d1.findElement(By.xpath("//*[#id='search_results']/table/tr/td[2]/a"));
for (WebElement link: links) {
link.click();
}
I am using GWT combobox with Select item (dropdown checkbox)
I want to make some items defaultly checked, but i cant find any solutions..
#Override
protected void success(List<warehouseDTO> t)
{
warehouse_list = t;
for (int i = 0; i < warehouse_list.size(); i++)
{
whl.put(warehouse_list.get(i).getId() + "", warehouse_list.get(i).getName());
}
selectItemMultiplePickList.setValueMap(whl);
selectComboForm.setItems(selectItemMultiplePickList);
}
On new "Article" (thing in warehouse) its good, but on edit i need to have checked by default.
Maybe its posible with setAttribute but cant find list of attributes.
Thanks
You should use the following:
setValues(values);
Here values accepts multiple String values.
Now as you're doing:
whl.put(warehouse_list.get(i).getId() + "", warehouse_list.get(i).getName());
your key for the combobox will be warehouse_list.get(i).getId() and value will be warehouse_list.get(i).getName().
So to show multiple values as selected values, you need to pass multiple warehouse_list.get(i).getId() as values.
For example, if you want show first 3 values as selected, you can do the following:
selectItemMultiplePickList.setValues(
warehouse_list.get(0).getId(),
warehouse_list.get(1).getId(),
warehouse_list.get(2).getId());
I am working on a Windows Form that has multiple comboboxes. Depending on what is chosen in the first combobox determines what items are filled into the second combobox. The issue I am running into is if I choose ChoiceA in ComboBox1, ComboBox2 is clear()ed, then is filled with ChoiceX, ChoiceY, and ChoiceZ. I then choose ChoiceB in ComboBox1, ComboBox2 is clear()ed, but there are no choices to add to ComboBox2, so it should remain empty. The issue is, after choosing ChoiceB, there's a big white box with three empty slots in ComboBox2. So, basically, however many items are cleared N, that's how many empty slots show up after choosing ChoiceB.
This might be a tad confusing, I hope I explained it well enough.
-- EDIT Adding Code, hope it helps clear things up. BTW, mainItemInfo is another "viewmodel" type class. It interfaces back into the form to make updates.
private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownItem item = (DropDownItem)cmbType.SelectedItem;
if (!String.IsNullOrWhiteSpace(item.Text))
{
cmbBrand.Enabled = true;
btnAddBrand.Enabled = true;
mainItemInfo.FillBrands(new Dictionary<string, string> { { "Type", item.Text } });
mainItemInfo.SyncBrands(this);
}
}
public void FillBrands(Dictionary<string, string> columnsWhere)
{
// Clear list
Brands.Clear();
// Get data
StorageData storage = new StorageData(File.ReadAllLines(ItemsFilePath));
// Fill Brands
foreach (string type in storage.GetDistinctWhere(columnsWhere, "Brand"))
{
Brands.Add(type, new DropDownItem(type, type));
}
}
public void SyncBrands(IPopupItemInfo form)
{
form.ClearcmbBrand();
var brands = from brand in Brands.Keys
orderby Brands[brand].Text ascending
select brand;
foreach (var brand in brands)
{
form.AddTocmbBrand(Brands[brand]);
}
}
public void AddTocmbBrand(DropDownItem brand)
{
cmbBrand.Items.Add(brand);
}
public void ClearcmbBrand()
{
cmbBrand.Items.Clear();
}
Simply, you can add an item then clear the combobox again:
cmbBrand.Items.Clear();
cmbBrand.Items.Add(DBNull.Value);
cmbBrand.Items.Clear();
You should able to set the datasource of listbox2 to null to clear it, then set it again with the new data.
So, in pseudo-code, something like:
ItemSelectedInListBox1()
{
List futureListbox2Items = LoadOptionsBaseOnSelectedItem(item)
Listbox2.Datasource = null
Listbox2.Datasource = futureListBox2Items
}
That should refresh the list of items displayed in Listbox2 with no white spaces.
I was able to fix the extra space. I changed the Add and Clear methods to:
public void AddTocmbModel(DropDownItem model)
{
cmbModel.Items.Add(model);
cmbModel.DropDownHeight = cmbModel.ItemHeight * (cmbModel.Items.Count + 1);
}
public void ClearcmbModel()
{
cmbModel.Items.Clear();
cmbModel.DropDownHeight = cmbModel.ItemHeight;
}