Reputation: 13
I am doing automated tasks.
To finish my task, I want to execute 3 automatic clicks in the same pop-up. The last one fails many times. Sometimes it is not able to click or does it outside the button.
I have also tried thread.sleep and the problem continues.
My code:
WebElement boton = driver.findElement(By.xpath(PATH_BOTON));
WebDriverWait wait3 = new WebDriverWait(driver, 2);
wait3.until(ExpectedConditions.elementToBeClickable(boton)).click();
CSS selector or Javascript executor are better options?
Upvotes: 0
Views: 62
Reputation: 193338
To invoke click() thrice on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use the following locator strategies:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("PATH_BOTON"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("PATH_BOTON"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("PATH_BOTON"))).click();
Upvotes: 0
Reputation: 59
Most of the issues that I have encountered when testing with Selenium on buttons arise from where the button object begins on the html page. The span element itself sometimes begins before the button does so you end up clicking the empty span space instead of the button, if thats the case you may want to use the DRIVER.MoveByOffset(xInt, yInt).Perform() methods to move your pointer into place. As for your selector it may be preferal to use By.id("uniqueID") when you can, as only one unique id can be given so you know thats the object your grabbing for the test.
Upvotes: 1