Find element within another element using explicit wait



  • 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.



  • 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"))));
    ```


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2