0

I am trying to click on a button in which text="Settings" or text="SETTINGS" using ignorecase.

My code:-

    WebDriverWait wait = new WebDriverWait(driver, THIRTY_SECONDS);

    return wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Settings")));

How Can i click button with ignore case ? Is there a way to do it ?

Galet
  • 4,911
  • 14
  • 72
  • 136

2 Answers2

1

You can try the following xpath by using the translate() function and contains() function:

String xpath = "//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'settings')]"

This will select elements containing text "settings" or "Settings" or "SETTINGS". Your code will then be:

return wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
JRodDynamite
  • 11,607
  • 2
  • 40
  • 57
0

Another way is to get a list of all elements in the current activity, and use string moethods to check the Text attribute. just make sure that you use try - cat when you are check the Text field to avoid Exceptions.

Matan Perry
  • 67
  • 1
  • 1
  • 6