How can I get the selected option from a combo box using winium?
I used Select class from selenium. But it is throwing error like
"org.openqa.selenium.UnsupportedCommandException: 'getElementTagName'
is not valid or implemented command".
I used the following code:
Select select = new Select(driver.findElement(By.id("cmbLocation")));
String option = select.getFirstSelectedOption().getText();
Try this.
WebElement combo = winDriver.findElementById(autoID);
String option = combo.getAttribute("NameProperty");
The NameProperty changes with the value of selected option.
Related
I am using DevXpress 14.
I want to use only one form name "FrmViewer" which contain DocumentVier to load any report I want.
This is the code, the datasource is not null (debugged), but the message is "The document contain no page". I think I missed some method of the documentViewer to start print
public FrmViewer(PhieuNhap pn)
{
InitializeComponent();
RptPhieuNhap rpt = new RptPhieuNhap();
rpt.DataSource = pn.ChiTietPhieuNhap;
rpt.nhacungcap.Value = pn.NhaCungCap.TenCC;
rpt.sophieu.Value = pn.SoPhieu;
documentViewer1.PrintingSystem = rpt.PrintingSystem;
}
You most likely need to call rpt.CreateDocument();
See here for more details:
https://www.devexpress.com/Support/Center/Question/Details/Q528191
In a short time I will begin automating a web site that has ext.net controls in it. I actually tried to automate a simple scenario as a sample from "http://examples.ext.net/" site. Click > Form > Field Note > Overview but I couldn't manage to write text to simple note textbox. Could you provide a code sample that is working? I tried to get by XPath and other means that can be used with by class. If I try to get all the inputs I get them but SendKeys or Click methods don't work. I get Element Not Visible exception. Could you provide a code sample that is working?
IWebElement htmlElement = driver.FindElement(By.TagName("html"));
IList<IWebElement> inputList = htmlElement.FindElements(By.TagName("input"));
(I get all the inputs but I can't write note...)
I did the following in Java and you can easily convert it to C# if you choose to.
I use a utility method to first properly query for the correct element:
class Utils
{
public WebElement query(String componentQuery) {
String query = componentQuery;
String cmd = String.format("Ext.ComponentQuery.query('%s')[0]", query);
String js = "return " + cmd + ".id;";
String id = (String) ((JavascriptExecutor) driver).executeScript(js);
return driver.findElement(By.id(id));
}
}
Then you can get your component here:
WebElement componentElement=Utils.query("Your-ExtJS-Query-for-the-component-goes-here"+".inputEl");
componentElement.sendKeys(valuesToSet)
I have a ListView inside of a Popup control (seems to be significant that it's in a Popup). The coded test is pretty basic, click a ToggleButton to open the popup, and then select an item in the ListView.
Except it seems that it can't find the item in the ListView.
System.ArgumentException: No row was specified as search container for
the control. To search for a cell control using 'ColumnIndex', you
must specify row as a container element or add 'RowIndex' to the
search property of the cell. Parameter name: SearchProperties Result
StackTrace: at
Microsoft.VisualStudio.TestTools.UITesting.ALUtility.ThrowDataGridRelatedException(String
errorString, String propertyName) at
Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfCell.GetUITestControlsForSearch()
at
Microsoft.VisualStudio.TestTools.UITesting.UITestControl.get_QueryId()
at
Microsoft.VisualStudio.TestTools.UITesting.UITestControlSearchArgument.get_SingleQueryString()
at
Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean
useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1
windowTitles, Int32& timeLeft)
The generated code is failing at this point
uIItemCell.Checked = this.MyListBoxCellParams.UIItemCellChecked;
where uIItemCell comes from this property
public WpfCell UIItemCell
{
get
{
if ((this.mUIItemCell == null))
{
this.mUIItemCell = new WpfCell(this);
#region Search Criteria
this.mUIItemCell.SearchProperties[WpfCell.PropertyNames.ColumnHeader] = null;
this.mUIItemCell.SearchProperties[WpfCell.PropertyNames.ColumnIndex] = "1";
this.mUIItemCell.WindowTitles.Add("CodedUITestWindow");
#endregion
}
return this.mUIItemCell;
}
}
So I guess this is where the criteria should be specified, but what how? And should row be hard coded somehow? Why didn't the test editor set the row?
If it helps, this is the .ctor where UIItemCell (above) is specified, seems like more search params
public UIMyCellDataItem(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[UITestControl.PropertyNames.ControlType] = "DataItem";
this.SearchProperties["HelpText"] = "MyCell's helptext property, this is correctly specified, but the HelpText is used only as a tooltip";
this.WindowTitles.Add("CodedUITestWindow");
#endregion
}
Thanks
I've normally seen ListView treated as a List, and the items as ListItem. You might want to use inspect.exe or the UI Test Builder to look at the properties. You can try to manually code the control. Sorry for posting speculation as an answer. Too long to be a comment.
WpfWindow PopUpWindow = new WpfWindow();
PopUpWindow.SearchProperties[WpfWindow.PropertyNames.Name] = "Pop Up Window Name";
WpfList List = new WpfList(PopUpWindow);
List.SearchProperties[WpfList.PropertyNames.Name] = "List Name";
WpfListItem ItemToSelect = new WpfListItem(List);
ItemToSelect.SearchProperties[WpfListItem.PropertyNames.Name] = "List Item Name";
// Click button to activate pop up window
ItemToSelect.Select();
// Creating the controls.
WpfWindow mainWindow = new WpfWindow();
// Add search properties.
WpfTable table = new WpfTable(mainWindow);
// Add search properties
WpfRow row = new WpfRow(table);
// Add search properties.
WpfCell cell = new WpfCell(row);
// Add search properties.
// Just adding the table and row as containers.
row.Container = table;
cell.Container = row;
}
I just cant get this to work.
I have a datagridview in winforms and in this one of my columns is a DataGridViewComboBoxColumn.
In my constructor I set it up like so
DataGridViewComboBoxColumn column = (DataGridViewComboBoxColumn)RectangleGrid.Columns["Material"];
DataTable data = new DataTable();
data.Columns.Add(new DataColumn("Value", typeof(int)));
data.Columns.Add(new DataColumn("Description", typeof(string)));
foreach (Materials M in DataStructure.Active.Active_Materials)
{
data.Rows.Add(M.MaterialNr, (M.MaterialNr + 1).ToString() + " " + M.Material.Name);
}
column.DataSource = data;
column.ValueMember = "Value";
column.DisplayMember = "Description";
And it actually works well except that nothing is selected in the drop down box which I want. I have googled this and for instance tried this approach: http://goo.gl/kBy8W but with no go because EditingControlShowing only happens when i click the box and not when it first comes up (so I can set selected index once it's clicked but thats no good).
The CellFormatting version at least changes the value but it just puts a string there rather than my first index from my data source.
I also tried this
column.DefaultCellStyle.NullValue = data.Rows[0]["Description"];
column.DefaultCellStyle.DataSourceNullValue = data.Rows[0]["Value"];
and that seemed to work but then when i selected the first index in the dropdown (so drop the dropdown down and then select the first index and then deselct the cell) I got an error from ParseFormattedValue where it says it cannot convert "value" to system.String.
There was this which seemed to be on the right track but i could not get it to work: http://goo.gl/VevA3
I ended up "solving" it in a very dirty solution that I don't like but it sort of works.
I had my datagridview bound to a datatable (not database) so what i did was i connected an event handler to the TableNewRow event in the datatable.
then i did this in that event handler
private void NewRectangleInserted(Object sender, DataTableNewRowEventArgs e)
{
if (e.Row[0].ToString() == "")
{
e.Row[0] = 0;
}
}
So basically when a new row is created I set the value of the combobox to 0 unless the user created the row by adding a value in that particular cell (why i check if it equals "")
The result is that as soon as you highlight a new line or any cell in a line the combobox is filled in. however the new line at the botton still has a blank combobox until you highlight it.
not perfect but a lot better. to bad it had to be done with a hack!
Hi I am new to C#. I have tried following way to add new item to my bound ComboBox but it won't give any result.
Is it possible to add new item to bound ComboBox (Here Problem is ID is Bigint data type but I want to add Select ID)?
If it is possible, please provide piece of code
try
{
objSqlExecute.OpenConnection();
string strQuery = objQueryManager.GetEmployeeRecords();
//Add Extra Items to combo Box
cmbEmployeeID.Items.Add("Select Id");
DataTable dtEmployee = objSqlExecute.GetRecordExecution(strQuery);
// DataRow dtNew = dtEmployee.NewRow();
// dtNew["ID"] = "Select ID";
// dtNew["FName"] = "";
//dtEmployee.Rows.InsertAt(dtNew, 0);
cmbEmployeeID.DataSource = dtEmployee;
cmbEmployeeID.DisplayMember = "ID";
cmbEmployeeID.ValueMember = "FName";
}
try
{
objSqlExecute.OpenConnection();
string strQuery = objQueryManager.GetEmployeeRecords();
//Add Extra Items to combo Box
DataTable dtEmployee = objSqlExecute.GetRecordExecution(strQuery);
cmbEmployeeID.DataSource = dtEmployee;
cmbEmployeeID.DisplayMember = "ID";
cmbEmployeeID.ValueMember = "FName";
cmbEmployeeID.Items.Insert(0, "None Selected");
}
Did you try your query to make sure it returns values? returning multiple records, single or none?
Do you want to add ONE new item at random intervals?
Or else do you have an option to INSERT all items at once?
Can you try adding toString() for converting BigInt?
Notes:
The arcticle here gives an insight to add a new item to a combobox using sql.
Looking at the questions you are posting, to see a sample of how to use ListItems in this scenario, you could refer to the web link.