Reputation: 1069
My page contains advance search link in which after filling the search criteria, a loader appears which loads my result on the basis of search criteria and next I need to perform delete.
My script run so fast that it doesn't wait for loader to disappear and click on delete which should not happen since their is no record which matches my search criteria.
Code which I used-
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Anyone who can help me with wait for this kind of process.
Let me know in case of any clarification.
Upvotes: 1
Views: 393
Reputation: 11
If you know the element of the loader (per example, classname="spinner
"), you could also wait for the invisibility of that element.
Try the following code:
WebDriverWait wait = new WebDriverWait(driver, 20);
By loadElement = By.className("spinner");
//wait until loader is gone
WebDriverWait.until(ExpectedConditions.invisibilityOfElementLocated(loadElement));
Upvotes: 0
Reputation: 193058
Since on filling the search criteria a loader appears which loads your results on the basis of search criteria and next you need to perform delete, so we have two approaches to solve this issue.
In the first approach, we would wait for the loader to disappear
and next click on the intended WebElement
to Delete
. We will be implementing this approach through WebDriverWait
with ExpectedConditions
set to invisibilityOfElementLocated
as follows:
WebDriverWait wait10 = new WebDriverWait(driver, 10);
wait10.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("xpath_of_loader")));
driver.findElement(By.xpath("xpath_delete_button")).click();
In the second approach, we would wait for the WebElement
as delete button to be clickable and next click on the intended WebElement
to Delete
. We will be implementing this approach through WebDriverWait
with ExpectedConditions
set to elementToBeClickable
as follows:
WebDriverWait wait11 = new WebDriverWait(driver, 10);
WebElement element11 = wait11.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_delete_button")));
element11.click();
Upvotes: 2
Reputation: 4739
Use this is as sample first I have to wait for About
link to be clickable so I have use Explicit wait and then wait for Our products
link to be clickable.
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.google.com");
WebDriverWait wait =new WebDriverWait(driver, 20);
WebElement aboutLink= wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.linkText("About"))));
aboutLink.click();
WebElement producttLink= wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//a[text()='Our products']"))));
producttLink.click();
Upvotes: 0
Reputation: 4739
Use Explicit wait, Please used it as sample example:
WebDriverWait wait = new WebDriverWait(driver, 20);
By element1 = By.xpath("path of element");
// get the button1 element
WebElement button1= wait.until(ExpectedConditions.presenceOfElementLocated(element1 ));
Upvotes: 0