Please give the below statement a try:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Filters']/ancestor::section//*[text()='SAMSUNG']")));
CodePudding user response:
@Codeception See the following code. I have given the explanation within my code as comments.
WebDriverWait wait = (new WebDriverWait(driver, Duration.ofSeconds(10)));
driver.get(
"https://www.flipkart.com/search?q=fridge&otracker=search&otracker1=search&marketplace=FLIPKART&as-show=on&as=off&as-pos=1&as-type=HISTORY");
// Waiting for the visibility of Samsung Brand before clicking it.
WebElement samsung = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//div[text()='Brand']/parent::div//following-sibling::div//div[@title='SAMSUNG']")));
samsung.click();
// Since the page is getting refreshed after above action, to avoid the
// StaleElemenetReferenceException,
// waiting for Samsung checkbox to be selected.
wait.until(ExpectedConditions.elementSelectionStateToBe(
By.xpath("//div[text()='Brand']/parent::div//following-sibling::div//div[@title='SAMSUNG']//input"),
true));
// By the time above action happens, Capacity is already available so not
// waiting it.
WebElement capacity = driver.findElement(By.xpath("//div[text()='Capacity']/parent::div"));
capacity.click();
// Waiting for the visibility of a particular option to be visible.
// In the below case waiting for visibility of "251 - 300 L" option
WebElement specificCapacity = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//div[text()='Capacity']/parent::div//following-sibling::div//div[@title='251 - 300 L']")));
specificCapacity.click();