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.

asked Nov 27, 2019 at 15:41

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"))));
answered Nov 28, 2019 at 11:44
1
  • Thank you! Also found out that I can use something like this: wait.until(ExpectedConditions.visibilityOfNestedElementsLocatedBy (lastMessage, By.xpath(xpathDeliveryStatus))); Commented Nov 28, 2019 at 13:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.