0

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.

123josh123
  • 147
  • 9
  • is the xpath right? can you add a condition isEnabled() before clicking? – itronic1990 Apr 21 '22 at 13:04
  • Used both xpath and css to locate the element. I used the function isEnabled and it returns false. The enabled mode is null. The thing that bugs me the most is why on debugging, when I manually click it doesn’t respond. Also, the step successed, but on screen the form is not being sent – 123josh123 Apr 21 '22 at 13:06
  • Have you tried ? WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.elementToBeClickable(locator)) – Akzy Apr 21 '22 at 13:15
  • Yes I have this by default in my method before executing click command, with different timeout given. Tried 10 it didn't work. – 123josh123 Apr 21 '22 at 13:33
  • Check the javascript attached to the submit button. your automation is doing something that is clearly not being detected by the javascript implementation – Claudio Batista Apr 21 '22 at 14:11
  • Ok, maybe something broken with the button? I will ask the developers – 123josh123 Apr 21 '22 at 15:02
  • How are you setting the text input? If you do that in js it might not fire the event it needs to update – pguardiario Apr 22 '22 at 02:33
  • When putting text, the send button becomes available to click. While stopping the automation and trying to click manually it doesn't work. So not Selenium method will help. But if I try manually from the start it works, or if I close the form and open a new form – 123josh123 Apr 24 '22 at 05:15
  • what is the error you are seeing in the console while clicking? – Jayanth Bala May 11 '22 at 07:23
  • there is no error, it clicked but nothing happened, didn't close the form – 123josh123 May 11 '22 at 07:25

2 Answers2

1

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")))); 
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Unfortunately, each Selenium method I use fail. The issue here is different and weird, only at automation the button is not clickable. I tried clicking on it multiple of times but it's not clickable. Manually works perfect. And if I close the form and open a new one it works – 123josh123 Apr 24 '22 at 05:18
0

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