0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

selenium pointer offsets are usually from the top left corner of the element you are selecting.
0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.