Element not visible when site opened through Automation



  • I have to check elements of an igniteBar on a webpage. When opened manually, the ignite bar appears with icons and operational (On mouse hover icon expands showing texts). Here is the html

    <div class="IgniteBar" data-experiment-id=" ">
    <!-- Used for A/B testing -->
    <!-- Old IgniteBar -->
    <ul class="IgniteBarV1 visible" data-total="6" style="">
    <li>...</li>
    <li>...</li>
    <li>...</li>
    </ul>
    <!-- New IgniteBar -->
    <div class="igniteOverlay"></div>    
    </div>
    

    But when I open the same page through my Automation code using webdriver, the ignite bar is completely absent. Html that time is this:

    <div class="IgniteBar">
    <!-- Used for A/B testing -->
    <!-- Old IgniteBar -->
    <!-- New IgniteBar -->
    <div class="igniteOverlay"></div>
    </div>
    

    I have applied all kinds of waits, thread.sleeps and the page loads completely, tried on faster network yet the behaviour is same - element does not appear through automation while manually it appears all the time. What kind of issue is this?



  • It could be issues with loading the element in DOM or may be that element appears once you preform action on some other element. So make sure you are going in right way as you are doing manually.

    Introduce Explicit Wait here to check different condition.

    To check whether element present in DOM :

    new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("ul[class='IgniteBarV1 visible']")));
    

    And to check visibility :

    new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("ul[class='IgniteBarV1 visible']")));
    

    In your case it seems visible attribute makes the element visible. So you can try to check whether element is there but not visible

    new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("ul[class='IgniteBarV1']")));
    

    And element present then check for visibility as below:

    new WebDriverWait(driver, 20).until(ExpectedConditions.attributeContains(By.cssSelector("ul[class='IgniteBarV1']"), "class", "visible"));
    

Log in to reply
 

Suggested Topics

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