This is the button of the page I need to click:
<div _ngcontent-jnk-c107="" class="btn btn-primary btn-outline" tabindex="0" ng-reflect-router-link="/opportunity/1">VIEW</div>
I can't use the text view in the locator as there are other 22 buttons in the same page with the same text.
The only difference between them is that router link, which I don't know how to call. I already tried with Link text and partial link text, with no results.
CodePudding user response:
In case ng-reflect-router-link
attribute value is unique for this element you can use the following XPath locator:
//div[@ng-reflect-router-link='/opportunity/1']
CodePudding user response:
To click()
on the element with text as VIEW with respect to the ng-reflect-router-link
attribute you can use either of the following Locator Strategies:
Using cssSelector:
driver.findElement(By.cssSelector("div.btn.btn-primary.btn-outline[ng-reflect-router-link='/opportunity/1']")).click();
Using xpath:
driver.findElement(By.xpath("//div[@class='btn btn-primary btn-outline' and @ng-reflect-router-link='/opportunity/1']")).click();
However, as the element is a Angular element, to click()
on the element you need to induce WebDriverWait for the elementToBeClickable()
and you can use either of the following Locator Strategies:
Using cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.btn.btn-primary.btn-outline[ng-reflect-router-link='/opportunity/1']"))).click();
Using xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='btn btn-primary btn-outline' and @ng-reflect-router-link='/opportunity/1']"))).click();