I'm running some simple form tests where values are added fields.
After each value is added to a field:
input.SendKeys(value);
I want to check the value in the field is correct. This may sound unusual but the field may have an ajax search attached and if the search doesn't pull back a match, the field will be empty.
I've tried testing the text value of the WebElement after sending the keys but it always seems to be empty:
bool match = input.Text.Equals(value);
// input.Text always seems to be an empty string
I'm using Selenium 2 with the WebDriver - is there another way to perform these checks? Is there a particular reason why the WebElement is empty even if the SendKeys successfully prints a value (actually in the browser) in to the WebElement (textbox)?
Any help would be grateful.
Explanation: sendKeys method was expecting an argument of type char sequence but we pass null which is invalid. So it throws IllegalArgumentException. Only local connections are allowed. Explanation: In this case, sendKeys method will not be able to identify null before it is processed for typing.
If we encounter issues while working with the sendKeys method, then we can use the JavaScript Executor to input text within an edit box. Selenium can run JavaScript commands with the help of the executeScript method. JavaScript command to be used is passed as a parameter to this method.
What Is Selenium sendKeys() Method? Selenium provides sendKeys() method to input content in editable text fields or password fields in a webpage. These fields are like the typical web elements present on the web page that can be identified using any of the Selenium locators.
We can set value to input webelement using Selenium webdriver. We can take the help of the sendKeys method to enter text to the input field. The value to be entered is passed as an argument to the method.
It may be possible that the text value that you are entering is assigned as a "value" attribute of text box and not as "text"
input.sendKeys(enteredValue)
String retrievedText = input.getAttribute("value");
if(retrievedText.equals(enteredValue)){
//do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With