2

I need to verify that a specific string of text is present on webpage and check the number of occurences in LeanFT. I have tried code below to verify if text is present:

browser = BrowserFactory.launch(BrowserType.CHROME);
browser.getVisibleText().contains("Success");
JJT
  • 186
  • 1
  • 13
plaidshirt
  • 5,189
  • 19
  • 91
  • 181

1 Answers1

2

I don't think getVisibleText on Browser is the best fit for the problem you're facing. AFAIK getVisibleText uses OCR and not the application's underlying technology.

A better way, I think, would be to identify the Web.Element that contains "Success". If you don't want to bother getting the specific element you can use the Page's text property.

I'm not familiar with LeanFT's Java SDK but in JavaScript it would be written like this:

expect(browser.$(Web.Page({})).text()).toContain("Success");

Edit: according to comments (thanks @Adelin), the Java equivalent is:

browser.getPage().getText().contains("Success");
Motti
  • 110,860
  • 49
  • 189
  • 262
  • 1
    on Java SDK you need to get the page `browser.getPage()` on which you can call `getInnerText()`. To sum up: `browser.getPage().getInnerText().contains("Success");` – Adelin May 14 '18 at 13:16
  • indeed `getVisibleText` uses OCR, which means that **(1)** will only work in windows OS **(2)** it might return `5uccess` because that's what OCR may have recognized. So yeah, better use `innerText` directly – Adelin May 14 '18 at 13:18
  • @Adelin : Is it possible to get back number of occurences too? – plaidshirt May 14 '18 at 13:19
  • @plaidshirt as `getInnerText` returns a string, same rules apply, so you could use [these answers](https://stackoverflow.com/questions/275944/java-how-do-i-count-the-number-of-occurrences-of-a-char-in-a-string) – Adelin May 14 '18 at 13:20
  • @Adelin: `getPage()` doesn't have `getInnerText()` method, cannot resolve it. – plaidshirt May 14 '18 at 13:25
  • 1
    Indeed looks like it's called [`getText()`](https://admhelp.microfocus.com/leanft/en/14.03/JavaSDKReference/index.html). Sorry for misleading you. – Adelin May 14 '18 at 13:28
  • @Motti : I tried it, text is present on page, but it can't found it. I tried `browser.getPage().getText()` too, but output seems empty. I assume, it should give all the text from page. – plaidshirt May 15 '18 at 09:59
  • @plaidshirt, does the page contain frames? If so you need to get text from the relevant frame. – Motti May 15 '18 at 10:31