-1

In Android, I want to test PDF which contains terms and conditions, but this displayed inside WebView. I am able to switch to WebView, I am using below code.

String strWebContextName = getContexts().stream().filter(ctx -> ctx.contains(“WEBVIEW_”)).findAny().orElse(null);
if (Objects.nonNull(strWebContextName)) {
((AndroidDriver) getBaseMobileDriver()).context(strWebContextName);
}

Then locate the script tag and get the content

@FindBy(xpath = “//script[@type=“text/javascript” and contains(text(),”_init")]")
private WebElement webElementPdfPath;

String htmlCode = (String) ((JavascriptExecutor) getBaseMobileDriver()).executeScript(“return arguments[0].innerHTML;”, webElementPdfPath);

After this I don’t know how to proceed? Please help

DeepakVerma
  • 179
  • 1
  • 3
  • 14

1 Answers1

0

In my experience with verifying PDF's in a WebView is that there is only limited you can search for with selectors. I'm used to only class or type attributes of the PDF container. I have never been able to search for specific text in an PDF with XPath (PDF's are also not part of the HTML but more an extension which opens the document).

Try a simpler XPath: //script[@type='text/javascript']. This way you know the PDF is opened, but that's all.

I've done this with desktop browsers as well. For browsers, there is no way to identify inner PDF elements, but only limited to: //embed[@type='application/x-google-chrome-pdf']. If I needed to verify the PDF with conditions I've used SikuliX image recognition for instance.

kenneth
  • 478
  • 4
  • 11