Search code examples
javacssseleniumidefluentlenium

Selenium IDE locator doesn't work in Selenium 3.3.1 Java


I have a web page which contains 2 links with the same classnames but with different div classes. The first one is invisible (it's in a dropdown menu) and the other one that I want is visible. So, I'm trying to locate the visible element.

His HTML :

 <div class="mainActionPanel">
   <a css="create"></a>
 </div>

The link has a dynamic ID. When I do a XPath search with the ID, I find rightly the element but it's deprecated because the button hasn't the same ID on each page.

I tried to locate the element with Selenium IDE, the following locator worked : css=div.mainActionPanel > a.create

The problem is with the locator that I showed above. When I try to find the element, I always have this exception :

NoSuchElementException : Element By.cssSelector: css=div.mainActionPanel > a.create (first) (LazyElement) is not present.

He doesn't find it. I tried several syntax like an example in the FluentLenium documentation ($("form > input[data-custom=selenium]") but it doesn't worked.

Moreover, the el(".create").click() is throwing an ElementNotVisibleException because he selects the dropdown link.

How can I find the right element ?


Solution

  • Try using below:

     WebElement elem = driver.findElement(By.cssSelector("div.mainActionPanel > a"));
     WebDriverWait wait= new WebDriverWait(driver, 20);
    
     wait.until(ExpectedConditions.visibilityOf(elem));
    
     elem.click();