Selenium C# Webdriver How to detect if button is clicked - selenium

I am using selenium with IE to automate web testing. My webpage fills out a form and finally clicks a button. Code to click button is
driver.FindElement(By.CssSelector("td.ne-fieldvalues > input[type=\"button\"]")).Click();
8 out of 10 times, it Clicks but other time click command is never executed.
Is there way I can check if button was indeed clicked ? something similar to checkbox
if (!driver.FindElement(By.CssSelector("input[type=\"checkbox\"]")).Selected)
driver.FindElement(By.CssSelector("input[type=\"checkbox\"]")).Click();
I tried .Displayed and .Enabled and both these properties are always true.
Thanks for help.

To ensure that an action is performed on a click of a link or button, it is best to verify the resultant state of application. For eg. if I click on 'Log in' button after entering valid username and password, it will take me to my homepage, verify that homepage has loaded, else fail the click event. In case of invalid username/password, verify the warning message on login page itself.
To summarize, you have to validate the response to verify click event on any web element.
The least you can do is ensure that the element is clickable using ExpectedConditions.elementToBeClickable():
// In Java
WebDriverWait wait = new WebDriverWait(driver, timeOut);
wait.until(ExpectedConditions.elementToBeClickable(locator));

Related

How do you handle dynamic cookie buttons in Selenium?

I'm trying to click the 'Allow essential and optional cookies button' which pops up on Facebook.
button = driver.find_element(By.XPATH,"//button[#id='u_0_e_EQ']")
button.click
the error is that the id (u_0_e_EQ) changes every time the page is reloaded. Is there any way to get around this?
If the button label is unique, you can use it.
driver.find_element(By.XPATH,"//button[text()='button_label']").click

how to submit a form with submit button outside form

i already used all possible scripts and i cannot click this button
element location
Submit
Did u try webelement in selenium Xpath=//tagname[#attribute='value'] ?

I want to test a submission form but the click on the submit button calls on a api from a different domain in Cypress

Lets say I want to automate a lead form with name and number in cypress,
I click on Submit button
The BaseUrl is https://localhost:8080
On clicking the Submit button manually, an API is triggered with URL https://localhost:9010
But in Cypress
Api is not triggered , and no action occurs on clicking the submit button .
Can somebody give a solution or a workaround for this issue??

Button not getting enabled upon selection of value from drop down in Selenium

There is a "Save" button in my application which is enabled upon selection of a value in a dropdown i.e. "Language".
When using Selenium for this, even after selecting this value, the button is not enabled, and hence the test fails, since Selenium is not able to click on the disabled button.
When this dropdown is manually selected the button is enabled.
For selecting the value from drop down i am using "Select" class.
How can i handle this scenario
you can try using javascript executor which will execute to turn button enabled from disabled condition,
WebElement btn= driver.findElement(By.SELECTOR("LOCATOR"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].removeAttribute('disabled')",btn);

Cannot click Submit button on Selenium IDE

I am having trouble getting Selenium IDE to click the Submit button on one of my webforms after having selenium open and fill out the form. I am using the clickAndWait command and identifying the button by its ID:
<td>clickAndWait</td>
<td>id=ctl00_ContentPlaceHolder1_OSVFHResults_btSave</td>
<td></td>
Interestingly, if I write a script that simply opens the form and clicks the submit button without filling it out, I am not having any problems. My problem is coming specifically after I've asked Selenium to fill out the form. Additionally, if I try to manually click the submit button, it doesn't work if the Selenium script to fill out the form was run before my manual input. If I manually open and fill out the form, I have no problems clicking submit, and Selenium works for all of the other form's submit buttons on the site. Anyone have any ideas?
Instead of filling form with type command you can try typeKeys one. It simulates keystroke events on the specified element, as though you typed the value key-by-key and probably enable your submit button.
It sounds like some javascript event unrelated to click() (such as mouseover or onkeydown) is attached to one or more of the form fields and is responsible for enabling the submit button.
You'd have to look at which exact events are being fired, either by looking at the source with something like firebug, or by using a javascript debugger. Then modify your Selenium script to make sure the same events get triggered.
After type the values in the form just try "ClickAtandWait" instead of "clickandWait"..i also face the problem once and it gave hands once..
selenium.clickAtandWait("locator", "position");
if you know the exact "position" just put it, otherwise leave it as an empty string.