How can I get the file content in Selenium?

We have Collabora setup through an iFrame on our site and I’m trying to write some automated tests to check it’s working correctly.

So far I’ve been able to fully interact with the Collabora editor but to do a full e2e test I’d like to open a saved document and check the contents of the file.

No matter what I try I just can’t seem to find a selector I can use to get the file contents, I was wondering if anyone here can help me?

Is there anything I can do to get the file content in my test?

@KevSmith Welcome to the Collabora online forum!

The Collabora online editor uses a canvas element to render document contents, which makes it difficult to directly select or inspect the text using traditional DOM selectors. However, you can work around this limitation by using the following approach:

  1. Select All Text: Use the Ctrl + A (or Cmd + A on Mac) keyboard shortcut to select all the text in the document.
  2. Copy the Text: Use the Ctrl + C (or Cmd + C on Mac) keyboard shortcut to copy the selected text to the clipboard.
  3. Access Clipboard Content: You can then access the clipboard content in your automated test to compare it with the expected values.

Here’s a basic outline of how you might implement this in an automated test script:

  1. Focus on the iFrame: Ensure your script focuses on the iFrame containing the Collabora editor.
  2. Send Keyboard Shortcuts: Simulate the Ctrl + A and Ctrl + C keyboard shortcuts to select and copy the text.
  3. Read Clipboard Content: Retrieve the clipboard content for verification.

I hope this helps! Feel free to reach out if you have further questions or run into any issues.

Genius! why didn’t I think of using the clipboard, thanks I’ll try that now!

1 Like

@KevSmith you’re welcome. For reference, check out how we do it using Cypress, which may help: Cypress Tests in Collabora Online.