1

I am unable to locate the proper element for a BI dashboard pane that has the same class

<a class="mi-title" deatta-no-in="inTitleShowed('folder')" daetta-ni-href="" data-ng-bind="navverTreeItemScope.listItem.title" style="" xpath="1">Staging - ALCDE</a>`

They all look like the above element and the only thing that change is the dashboard name Staging - ALCDE

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
PeaceT
  • 63
  • 1
  • 7

3 Answers3

0

You can try this :

WebElement elmt = driver.findElement(By.xpath("(//*[@class='mi-title'])[1]"));

Change [1] to [2] etc, this is the number for the element if there is more than one.

frianH
  • 7,295
  • 6
  • 20
  • 45
  • Hi this code did not work it returned an error message xception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"(//*[@class='mi-title'])[1]"} – PeaceT Aug 16 '19 at 14:45
0

You can also use this xpath for identifying the element

driver.findelement(By.xpath("//*[@data-ng-bind='navverTreeItemScope.listItem.title']"))
0

As you mentioned the only thing that change is the dashboard name i.e. Staging - ALCDE so you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • linkText:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Staging - ALCDE"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='mi-title' and text()='Staging - ALCDE'][starts-with(@data-ng-bind, 'navverTreeItemScope')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thanks for your swift help, both codes did not work. I didn't get any error message this time and it did not click on the dashboard. Please, any reason why? Thank you – PeaceT Aug 16 '19 at 14:28
  • @PeaceT What do you mean by **did not click**? Your question and this answer both are for **locating** the element. Do you want to `click()`? – undetected Selenium Aug 16 '19 at 15:02
  • apologies for not being clear, Yes I want to click on it as well. but when I added click(); to the code, I got a syntax error 'Type mismatch: cannot convert from void to WebElemen – PeaceT Aug 16 '19 at 15:50
  • @PeaceT Checkout the answer update and let me know the status. – undetected Selenium Aug 16 '19 at 16:22
  • @DebanjabB Woohoo its work. Thank you so much you are the best. I am working on a professional project. Please, I will reach out again. Thank you again – PeaceT Aug 16 '19 at 18:39
  • Hi Please, I ran into another problem. I posted it on my page. Please, can you help me look into it? Thanks again – PeaceT Aug 16 '19 at 20:45