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.
Related
I want make automation for this web site
in this web site 3 text box are here check image
1st text box x path is /html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]
here is my code
driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");
when I run this code I got this error
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
How can i fix it? I hope my xpath is correct.
The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to true
WebElement dropdown = driver.findElement(By.xpath("//*[#id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(#class, 'ui-select-search')]"));
textField.sendKeys("rio salon");
You can click in an input field with a div or span tag, but you cannot type in the field. So, your XPath must be written with an input tag if you want to sendkeys or type in an input field. For example:
//input[contains(#placeholder,'Site')]
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 written a selenium data driven code, which will fetch data from the excel file and will ,fill up in the web page.
the Webpage contains
drop downs for Country ,State and City,
Text Field 1 and Text Field 2
Add/update Button and Clear Button
Steps
1-select country,state,city ,enter text field 1 and Add/Update button.
Issue
When I perform above action, when Add/update is clicked ,I want page to wait until again starting the loop ,so that the country drop downs resets again.
as of now it is not waiting and causing even a new country is selected the state drop-down shows previously selected country's provinces.Example(If I select India and provinces for the 1st record, than next time for United states the "State-drop down" displays ,Indian States but not the United States"
I tried using wait until technique even the driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS), even thread.currentthread.sleep
but none of them are consistent as after some records I am getting error as element not found because of the above mentioned issue.
I want post Add/update button is clicked the driver to wait till it again resets the page with default value of the country set Secondly when I pass a value for the country the driver again to wait so that it can load it corresponding States .
I hope this could be handled in this way:
Step 1: Write small method where in you send a Webelement and the desired value that you need to select.
Step 2: In that method, before selecting a value from drop down, read the value from it and check for the desired value you looking for.
Step 3: If you don't find the desired value then wait for say 'x' seconds and then loop it again for desired value that you are looking for.
Step 4: Once you get desired value, select it and exit the loop.
By this above method, you can handle as many combo boxes as you like.
For reference: how to read values from combo box
In my opinion you should use some intelligent wait condition here so that it waits until the element gets activated or enabled.
Select any value from first drop down
Wait until page to be loaded completely
Wait until second drop down gets activated
Select any value from second drop down
Wait until page to be loaded completely
Wait until second drop down gets activated
If above solution doesn't work then go for 'refresh', code should be able to refresh the page before selecting any value from first drop down.
// Code to wait until page get completely loaded
public void waitUntilPageIsLoaded() {
ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(condition);
}
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?
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.