I have submit button, which is only one on the page, and it's in form.
html part:
<form class="search-form ng-touched ng-dirty ng-valid" novalidate="" style="" xpath="1">
<div class="row">...</div>
<div class="row">...</div>
<div class="row">...</div>
<div class="form__actions" xpath="1">
<div class="form__buttons">
<!---->
<div class="btn__wrapper">
<button class="btn btn__primary" type="submit">
Select My Car
</button>
</div>
</div>
</div>
</form>
So, I'm taking xpath:
//button[@type='submit']
I'm successfully pressing it via submit() (let me skip WebDriver init, its fine):
WebElement searchButton = driver.findElement(By.xpath("//button[@type='submit']"));
searchButton.submit();
(and some search performs)
But when I'm trying to press it via click()
WebElement searchButton = driver.findElement(By.xpath("//button[@type='submit']"));
searchButton.click();
it's not pressed in browser which is launched, and same time Junit test is green (not test, but just pressing button):
@Test
public void test() {
WebElement button = driver.findElement(By.xpath("//button[@type='submit']"));
button.click();
}
Can please someone explain, why submit() successfully presses button in such case, but click() - no. And I do not understand, why "test" is green, when we are trying to click(), but it was not performed, if looking on browser launched by driver.
UPDATED: I tried
WebElement button = driver.findElement(By.xpath("//button[@type='submit']"));
if (button.isEnabled()) {
button.click();
}
and
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(button)).click();
but still the same - submit() works fine, click() - does not.