2022-04-26

Locating an element within another element

public LocatedCarParksMap locateAndClickOnTheCardByAddressIndicator(String location) {
            List<WebElement> quoteCards = driver.findElements(By.cssSelector(".quote-card"));
    
            for (WebElement webElement : quoteCards) {
                WebElement locationElement = webElement.findElement(By.cssSelector(".quote-card-asset-location"));
                if (locationElement.getText().equals(location)) {
                    webElement.findElement(By.xpath(".rate-card-description")).click();
                }
                throw new NoSuchElementException();
            }
            return this;
        }

DOM

  1. Locating list of cards
  2. iterating through it and locating needed card by locating the element that contains the address i am looking for
  3. if address is the one i am looking for i am trying to find .rate-card-description within the same card element and then clicking on it to proceed further

I have debugged it and it does locates the address from the card however it cant locate an element within the yellow text are for me to click on

What i am doing wrong, thank you



No comments:

Post a Comment