0

Which locator can I use for the below?

<span class="tile-name ng-binding">Payment Partner</span>

Update from OP's comments:

Code trial 1:

driver.findElementByXPath("//span[text()='Payment Partner']").click(); 

Error:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible;

Code trial 2:

driver.findElementByCssSelector("Payment Partner").click(); 

Error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"Payment Partner"}

Code trial 3:

WebDriverWait wait = new WebDriverWait(driver, 20);wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath ("//span[text()='Payment Partner']')")));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Catia
  • 45
  • 5

2 Answers2

0

Following are variance that you can use for above HTML line :

  1. Xpath : //span[text()='Payment Partner']

  2. Xpath : //span[@class='tile-name ng-binding']

  3. Xpath : //span[contains(@class,'tile-name')]

  4. Xpath : //span[contains(@class,'ng-binding')]

  5. Xpath : //span[contains(@class,'tile-name') and text()='Payment Partner']

  6. CssPath : span[class='tile-name ng-binding']

I can add more If there would be parent element.

Hope this is helpful.

Sagar007
  • 848
  • 1
  • 13
  • 33
0

As per the HTML you have shared to to find the <span> tag, as the element is an Angular element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solution:

  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='tile-name ng-binding' and contains(.,'Payment Partner')]"))).click();
    
  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span.tile-name.ng-binding"))).click();
    

Update

As per the error update to invoke click() you can use the following solution:

  • xpath:

    WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='tile-name ng-binding' and contains(.,'Payment Partner')]")));
    ((JavascriptExecutor)driver).executeScript("arguments[0].click();", myElement); 
    

You can find a detailed discussion in Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your suggestions but none of the above works please see error: Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element ... is not clickable at point (152, 202). Other element would receive the click: ... (Session info: chrome=68.0.3440.106) – Catia Sep 10 '18 at 15:49
  • @Catia Checkout my answer update and let me know the status. – undetected Selenium Sep 10 '18 at 18:28
  • 1
    It worked with the updated solution.... Great job thank you so much, been stuck for days on this one. – Catia Sep 10 '18 at 19:41