Reputation: 2224
I am trying to automate functional testing of a web application using Selenium webdriver and Java. In the AUT, there is a 'Submit' button defined by the following html code
<button id="submitbtn" class="btn btn-primary" type="submit">Submit</button>
I use the following command to click the button.
driver.findElement(By.id("submitbtn")).click();
When I run the code, the webdriver can find the button but the click action is not performed (I can understand that webdriver can find the button because no exception is thrown and the I can see a selection on the button when the code is run). I tried different waits
new WebDriverWait(driver,60).until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("submitbtn"));
but not getting any positive result. If I use,
Thread.sleep(3000);
it works fine (but I want to avoid this code). I tried all other types of waits and action class,
Actions action=new Actions(driver);
action.moveToElement(driver.findElement(By.id("submitbtn"));
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("submitbtn")));
action.click().perform();
but no luck. Is there any way to achieve this?
Upvotes: 0
Views: 2018
Reputation: 934
A submit()
is an option driver.findElement(By.id("submitbtn")).submit();
. More information here
Upvotes: 0
Reputation: 3295
How about JavascriptExecutor?
WebElement element = driver.findElement(By.id("submitbtn"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Upvotes: 1