I have a standard form with 2 text boxes to fill and a submit button. The Submit button suppose to work after filling in the first mandatory text box. It works manually, but when running on the automation infrastructure, the element doesn't get clicked. The odd thing is that when debugging, the submit button is not clickable too, although it's not greyed out. I tried the 3 classic methods: Javascript:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Actions:
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
click:
element.click()
**Not working manually while in automation ** only when closing the form and creating a new one it works.
CodePudding user response:
To click() on any clickable element ideally you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following solutions:
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//elementXpath"))).click();
As an alternative, using Actions
class:
new Actions(driver).moveToElement(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//elementXpath")))).click().build().perform();
Another alternative, using JavascriptExecutor
:
((JavascriptExecutor)driver).executeScript("arguments[0].click();", new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//elementXpath"))));
CodePudding user response:
According to your steps an replays , may be there is a hidden popup or something block your elements ,so use WebDriverWait not only clickable but try to elementToBeSelected() , invisibilityOfTheElementLocated() or presenceOfAllElementsLocatedBy()
increase the waiting time to be able to detect the issues