-1

I am trying to locate the following element using href.

<a class="compliance-documents-link-text" target="_blank" href="api/Document/GetDocumentByType/25194300-f620-4cc9-a375-419b1ebfe729/1">
<span>Acceptance Criteria</span>
</a>

I have to use href="api/Document/GetDocumentByType/25194300-f620-4cc9-a375-419b1ebfe729/1" as I need to differentiate between different products that all have acceptance criteria but different doc links.

I currently have:

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@href ='api/Document/GetDocumentByType/8d844ee3-b9cc-4d5c-87ee-8363bf46164a/1']")));

but it cannot locate the element.

samwelsh
  • 1
  • 1

2 Answers2

1

Your XPATH is incorrect.

In your code your href value has '419b1ebfe729/14' at the end where as in question you have mentioned it as '419b1ebfe729/1' at the end.

Pankaj Devrani
  • 510
  • 1
  • 10
  • 28
0

The desired element is a dynamic element so to locate and click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • xpath 1:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='compliance-documents-link-text' and starts-with(@href, 'api/Document/GetDocumentByType/')]//span[text()='Acceptance Criteria']"))).click();
    
  • xpath 2:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='compliance-documents-link-text' and starts-with(@href, 'api/Document/GetDocumentByType/')][./span[text()='Acceptance Criteria']]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352