Reputation: 1
I am trying to locate the element for this:
<a ng-if="showLink && customer.partnerType == 2 && customer.isDirectCustomer" class="cp_text_link ng-binding ng-scope" ng-href="/?orgId=77bc101729ad844e39c4c1e17231c7e4&orgName=Attunix" href="/?orgId=77bc101729ad844e39c4c1e17231c7e4&orgName=ABC">
ABC
</a>
I tried the XPath and CssSelector but its unable to locate element. Can someone pls help me locate the element TIA
Upvotes: 0
Views: 75
Reputation: 193088
The desired element is an Angular element so to locate and invoke click()
on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Java based Locator Strategies:
partialLinkText
:
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("ABC"))).click();
cssSelector
:
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cp_text_link.ng-binding.ng-scope[ng-href*='orgId'][href$='ABC']"))).click();
xpath
:
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='cp_text_link ng-binding ng-scope' and contains(@ng-href, 'orgId')][contains(@href, 'ABC')]"))).click();
Upvotes: 0
Reputation: 1996
Simply use text:
driver.findElement(By.xpath("//a[contains(text(),'abc')]"));
Upvotes: 2
Reputation: 17
Try using class driver.findElement(By.cssSelector("a.cp_text_link"))
Upvotes: 0
Reputation: 168002
It is quite hard to come up with an exact locator without seeing the full code of the page, you're trying to automate.
From what I can see so far it makes sense to stick to ABC
text so try the following:
driver.findElement(By.partialLinkText("ABC"));
Or the equivalent XPath
driver.findElement(By.xpath("//a[contains(text(),'ABC')]"));
Upvotes: 1