My dropdown box is of type "Input" and its values are listed using table.I'm able to get the rows using following code.
WebElement table = driver.findElement(By.id("testTable"));
List<WebElement>tr_collection=table.findElements(By.xpath("id('testTable')/tbody/tr"));
Row text is retrieved only when the dropdown is clicked and text is displayed.Is it possible to get the text when it is hidden ?
The method WebElement.GetText() returns the text visible to a user. To get the hidden text, you can read the HTMLElement.textContent property. Though, I would recommend it in a testing context since it doesn't reflect a real usage.
To get the text with .GetAttribute:
string text = element.GetAttribute("textContent");
To get the text with .ExecuteScript:
string text = (string)driver.ExecuteScript("return arguments[0].textContent;", element);
Related
I have a Part Number field displayed as drop down list in my ASP.NET webform.
User will select part number and System will store the respective ID from part table.
Since this is dropdown list, user is not able to type the part number. I want to use a combobox so that user can enter the initial few digits, and then suggestions will pop up like in a dropdown list. Also I want to show error is the entered value by user is not in the database.
I am currently using asp-for and asp-items tag helpers to show data in dropdown.
Is there a way I can get to display combobox instead of dropdown list?
Thanks!
The Answer to above question can be found here:
Link: How to get the values of multiple choose dropdown box
Add the jquery Script from above link. for Select tag, use class as : multiple class="chosen-select" and finally add below script to show default value when input doesn't exist in database.
<script>
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});
</script>
I'm trying to fill a table using the selenium drivers and all the documentations I could find only shows how to retrieve data from the cells. I'm able to access my table cells using:
var rows = Driver.FindElement(By.Id("Products")).FindElements(By.XPath("id('Products')/tbody/tr"));
var cells = tableRows[1].FindElements(By.XPath("td"));
But I couldn't find any way to update the data that's in it. The "Text" property only has a Get method and the SendKeys() function doesn't work. How can I edit the cell's value?
As a side note, my cell contains an html "input", I've tried to access it with the FindElement function of the cell but for some reasons it cannot find it.
Generally speaking, SendKeys should work if the cell indeed contains the input element. But because you're also saying that you fail to find the input element, I suspect that the input element does not exist in each cell all the time. You should probably first click on the cell in order for the input element to appear on that cell. You should be able to verify it using the Dev Tools if you inspect the element before clicking it.
IWebElement doesn't provide a method to change text, but you could use a little bit of JS - something little like :
((IJavaScriptExecutor)Driver).ExecuteScript("document.getElementByXXXXX.innerHTML = "VALUE";");
https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IJavaScriptExecutor_ExecuteScript.htm
In the attached screenshot I want to read the value of title which is 'Title_6jOa'
But I'm unable to locate the element because text value is not present in highlighted area.
Any solution please.?
You should be able to locate the field by the class of the field, a CSS selector could be .x-frs-id-ivnt_Title
Then for reading the text that is typed into the field,
findElement(By.cssSelector(".x-frs-id-ivnt_Title")).getAttribute("value")
If the css selector .x-frs-id-ivnt_Title can't find the expected text box, try below xpath:
findElement(By.xpath("//tr[td[contains(., 'Title')]]/td/input")).getAttribute("value")
Please check the CSS selector and xpath manually in browser DevTool before change code.
Input Field Text values will not be be persisted in the Input Tag in Dev Tool.So,we cannot not use getText() Method and it can be extracted using the getAttribute() method as below or JavaScriptExecutor can be used (Using Selenium Web Driver to retrieve value of a HTML input)
Steps:
Identity the text field Web Element using any one of the unique locator
Use the getAttribute Method to get the value
Code :
WebElement titleInputElement=driver.findElement(By.xpath("//input[contains(#class,'x-frs-id-ivnt_Title')]"));
String value=titleInputElement.getAttribute("value");
#yong , #Subburaj Sorry tried yours way too, but getting no value.
Getting the value in below way perfectly.
Steps:
Double click in the text field. To get text selected.
Then copy the text to clipboard using Keyboard key ctrl+c
Copy the text
And Then the final step is reading the text from clipboard by below line of code in c#.
string clipboardExpectedText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);
How can I highlight my searched text without using the original text in lucene.net? I just want to used an index and the text is indexed by using the field termvector with postion offsets?
if you index your field with "Store.YES" and "TermVector.WITH_POSTIONS_OFFSETS"
you can use FastVectorHighlighter in contrib to highlight search results without referencing original text.
So I have a combobox - the designer code:
this.cmbStatusBox.Items.AddRange(new object[] {
"Ordered",
"Cooking",
"In-transit",
"Delivered"});
The formload code:
if (mainForm.boolEdit == true)
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Cooking",
"In-transit",
"Delivered"});
}
else
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Ordered"});
}
As you can see, I am trying to make the combobox have different values.
As things stand, i get both whats in the designer and in formload in the comboboxes.
How can i stop this?
I also have an edit function, so when i edit a record, i want the combo box to be populated by what is already saved.
Just a random question, can you stop the user entering a value that isn't in the combo box?
Thankyou
If you want to replace the current contents then you'll need to call
this.cmbStatusBox.Items.Clear();
before adding your new values.
ComboBox MSDN page
ComboBox.Items MSDN page
The DropDownStyle property also specifies whether the text portion can be edited.
Source
The values are:
Simple Specifies that the list is always visible and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list.
DropDown Specifies that the list is displayed by clicking the down arrow and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list. When using this setting, the Append value of AutoCompleteMode works the same as the SuggestAppend value. This is the default style.
DropDownList Specifies that the list is displayed by clicking the down arrow and that the text portion is not editable. This means that the user cannot enter a new value. Only values already in the list can be selected. The list displays only if AutoCompleteMode is Suggest or SuggestAppend.
Source
Just remove the items from the designer code.