1

I have following html element. using selenium i need to find the existence of the span class my-icon . Also findout the first div class is 'active'.Since the class contains multiple classes i was not able to find element by class.

<div class="inner my active">
    <div class="left-side">
        <span class="icon my-icon"></span></div>
    <div class="right-side">
        <span class="icon-connected"></span>       
        <button class="button manage">Manage Connection</button>
    </div>
</div>

1)Code used to find the existence of span class <span class="icon my-icon"></span> it is not working and getting element is not visible.

 WebElement ispresnet = driver.findElement(By.xpath("//span[contains(@class, 'my-icon')]"));
 boolean os = ispresnet.isDisplayed();
Psl
  • 3,830
  • 16
  • 46
  • 84
  • Hope this might help.. http://stackoverflow.com/questions/1604471/how-can-i-find-an-element-by-css-class-with-xpath – choz Jul 23 '15 at 04:13
  • For multiple classes you can use css & join classes by '.' In your case try-By.cssSelector("div>div>span.icon.my-icon") – Deepak Jul 23 '15 at 04:19

1 Answers1

2

You should probably wait for element to become visible:

WebDriverWait wait = new WebDriverWait(webDriver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.active span.icon")));

Note that I'm using div.active span.icon CSS selector here which would match the span element having icon class inside a div element having active class. Either the way I wrote the selector, or the explicit wait should help here.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195