Keep reading DIVS after skipping a single div with selenium webdriver

I want to skip the GoTop div class and continue counting the number of divs in the parent class.

<div class="parent">
      <div>
      <div>
      <div>
      <div>
      <div>
      <div class="GoTop">
      <div>
      some more div ......
    </div>

I tried the following, but all I get is size 5, please help

size = driver.findElements(By.xpath("//div[@class='parent']/div [not(contains(@class,'GoTop'))]")).size();
+4
source share
1 answer

Your verified code looks right, I think you should try using WebDriverWaitto wait until the divs element appears with a validated locator.

I suggest you try using By.cssSelector()to achieve the same as below: -

WebDriverWait wait = WebDriverWait(driver, 10);
int size = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("div.parent > div:not(.GoTop)"))).size();

: - , , ExpectedCinditions.numberOfElementsToBeMoreThan , , : -

WebDriverWait wait = WebDriverWait(driver, 10);
int size = wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("div.parent > div:not(.GoTop)"), 6)).size();
0

Source: https://habr.com/ru/post/1656029/


All Articles