'How to click on button when input type =Button in Selenium Web driver by using Java
How to click on button when input type is button , I am using below code, click on button is working but data is not saved.
driver.findElement(By.cssSelector("input[type='button'][value='Save']")).click();
driver.findElement(By.cssSelector("input[@type='button'][@value='Save']")).click();
driver.findElement(By.cssSelector("input[@type='button']")).click();
And below is the development code for your reference:
<input id="save_btn_expe" class="edit_forms_save_btn" type="button" value="Save">
Solution 1:[1]
WebElement setElement = driver.findElement(By.id("save_btn_expe"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click()", setElement);
OR
driver.findElement(By.id("save_btn_expe")).click();
OR
driver.findElement(By.xpath("//input[@id='save_btn_expe']")).click();
Solution 2:[2]
By considering your statement "click on button is working". You can use the submit method to post form data. You can use two other alternates for click. Following code is in c#:
driver.FindElement(By.Id("save_btn_expe")).submit();
// Send enter key on the element.
driver.FindElement(By.Id("save_btn_expe")).SendKeys(OpenQA.Selenium.Keys.Enter);
Before trying the above code, check manual save to make sure there is no bug on save.
Solution 3:[3]
Since it's an input tag element, though the type is button .click() or .submit() will not work. You have to provide the Enter key as an input. Use following code :
driver.findElement(By.xpath("//input[@id='save_btn_expe']")).sendKeys(org.openqa.selenium.Keys.ENTER);
I hope this will work for you, as it did for me.
Solution 4:[4]
if using for in DOM, the selector below work for me :
Selenide.$("label[for=\"save_btn_expe\"]").click();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hemant Kulkarni |
| Solution 2 | Elzo Valugi |
| Solution 3 | abhishek narayan |
| Solution 4 | YaaKouB |
