I have an "input"-WebElement that has a "onkeyup" AJAX call. (It's a order-amount field)
I want to check the error message that checks the amount entered against what's actually in stock with Selenium Webdriver in Java.
However, I think because of the "onkeyup" the input field always resets back to the defaul value "1" after the sendkeys from Webdriver. I tried with and without clear and also tried to check the field was empty after the clear.
Any idea how the field value reset can be prevent in spite of the "onkeyup"?
I found the solution here:
https://groups.google.com/forum/?fromgroups=#!topic/webdriver/UiV08YgUxSI
For me the Keys.BACK_SPACE did the trick
Doesn't work with WebElement.clear() and doesn't work without the clear() or BACK_SPACE.
Related
I read all the relevant threads in the forum, to no avail. I try to select an option in a dropdown in this hTML code:
<input name="tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails" type="text" id="tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails" class="async_list" autocomplete="off" data-ajax-id="CustomFieldLookup" data-ajax-allow-query="True" data-ajax-param1="143" data-ajax-param2="" data-selected-value="Pending">
So far, I am able to extract the current value with either options:
driver.FindElementByName("tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails").value
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").Attribute("data-selected-value")
For the input, I tried the following methods:
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").AsSelect.SelectByValue "Completed"
'That returns the error: "Unexpected TagName Error. Expected=select Got=input"
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").SendKeys "Completed"
'This writes the value in the dropdown but it cannot be saved
Any idea?
Many thanks in advance.
If sendkeys is working perhaps you may need to select the option from the dropdown in addition to typing it. I have run into scenarios where you need to select the option from the drop down after you have sent it. In a side note: I have noticed that having waits between inputs also helps.
Example
driver.FindElementByXPath("//*[#name='tv1ASSIGNMENT_CF!CF_TEXT035AssignmentDetails']").SendKeys "Completed"
driver.Wait (10)
driver.SendKeys keys.ArrowDown
driver.SendKeys keys.Enter
I have noticed that in some lists, you need to add a wild card in the send keys method to correctly retrieve the option and then do the selection.
I am trying to test a website using selenium(with java). On my website, there is an option to add a new class. When we click on the add new option button, a pop-up window will come and we can enter our new class name. But using selenium I cannot enter alphabets into the pop-up window. I can only enter numbers in that field. The field accept both alphabets and numbers when we enter the data manually. How can I add alphabets to the pop window in selenium?
Here I attach my code below :
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"modal-add\"]")));
driver.findElement(By.xpath("//*[#id=\"class\"]")).sendKeys("LKG");
driver.findElement(By.xpath("/html/body/section/div/div[3]/div/div/form/div[2]/button[2]")).click
screenshot of the field - Class_field_screenshot
As mentioned above you are not able to add alphabets in textfield using sendkeys function. I haven't heard this type of issue before please confirm that either that field accept alphabets or not. if that feild accept alphabets then try using another way like javascript executor to send text as mentioned below
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('#id').val("sendtext")");
Can you try Clipboard class for copy and paste string value in class field ? Make sure you click first in class text field and then use paste code. As you say by keyboard you are able to enter alphabet so try to use keys class too.In both cases your keyboard is going to use so may be it helps.
I have a Radcombobox in my application which has several check boxes in the combo box. What I wish to do is to fetch the text associated with the check box. I searched on internet and came to know that text can be fetched from name or value property in HTML code, but problem is that my HTML code does not have such properties.
HTML code:
input class="rcbCheckAllItemsCheckBox" type="checkbox"
Check All
What i wish to do is to fetch value "Check All".
Using code x = driver.findElement(By.xpath("/html/body/form/div[1]/div/div/div/input")).getText();, value returned is blank.
You can get the text through JavaScript API of Rad Controls. You can check the official documentation- http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/overview
Basically, you first locate the element in JS and then use the official control method, in your case get value method. You can also perform several other useful operations if you need to.
You can execute JS in WebDriver with the following code:
IWebDriver driver;
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("return document.title");
I have a set of checkboxes, If I check or uncheck them on the form the setCheckboxes method in Action form gets fired after it gets posted. But it doesnt fire when ALL the checkboxes have been unchecked. How do get it to do that?
The problem here is, if the checkbox is unchecked struts wont populate it.
if you are having the particular field as boolean in your form class you can use a javascript
function to find the unchecked checkboxes and try to append the value as false in the url.
eg.
http://youraction.do?checkBox1=false&checkBox2=false
this will solve your problem.
Instead of depending on javascript or some workaround to get false values to be sent, just assume the values will be false (override the reset() method to set all to false) and any that are checked will be submitted and setCheckbox() will be called.
Was there some other reason you wanted setCheckbox to be called?
Hi I am automating a webpage which contains multiple checkbox.
It clicks on a some checkbox and misses some checkbox.
This is my code.
Should I put a wait statement before the click to avoid this problem.
IWebElement ClickElement = Wait.Until((d) => webDriver.FindElement(By.Id(parameter1)));
ClickElement.Click();
Can you try making this change in your code -
In wait until function you are checking if the element exists by using findElement(By.Id(parameter1))
After finding the WebElement check if this is displayed by using isDisplayed() method with in the waitUntil function.
You can also check if it has already checked or not by using isSelected() method.