0

I have the following code:

List<MobileElement> messages = driver.findElements (By.id ("body_bubble")); //find all messages
MobileElement lastMessage = messages.get (messages.size () - 1); //get last message

// xpath query to check if the message is delivered
String xpathDeliveryStatus = ".//*[contains(@resource-id, 'delivered_indicator') or contains(@resource-id, 'read_indicator') or contains(@resource-id, 'sent_indicator')]"; 
MobileElement deliveryStatus = lastMessage.findElement (By.xpath (xpathDeliveryStatus));

I want to do the same except that I want to find the deliveryStatus variable using explicit wait.
So I want to find the deliveryStatus variable inside the lastMessage variable using
wait.until (ExpectedConditions.visibilityOfElementLocated (By.locator))

How can I do this?

I don't want to do it using one immense Xpath. Besides, I don't even know how to find the last element with the id body_bubble using Xpath, as the number of these elements is not fixed and always changing.

P.S. For example, in Python we can define WebDriverWait with an element in the constructor instead of driver: WebDriverWait(webelement, self.timeout)

Unfortunately, it does not work in Java.

1 Answer 1

1

Try something like this:

WebElement outerElement = driver.findElement(By.xpath("OTER_ELEMENT_XPATH"));
WebDriverWait waiter = new WebDriverWait(driver, 100);
WebElement innerElement = waiter.until(ExpectedConditions.elementToBeClickable(outerElement.findElement(By.xpath("./INNER_ELEMENT_XPATH"))));
1
  • Thank you! Also found out that I can use something like this: wait.until(ExpectedConditions.visibilityOfNestedElementsLocatedBy (lastMessage, By.xpath(xpathDeliveryStatus)));
    – LexSav
    Commented Nov 28, 2019 at 13:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.