3

I'm just trying to figure out if anyone has successfully completed this. From what I'm seeing id's are randomly generated and not static for each test run.

Causing issues identifying iframes on the page, and practically everything is in a iframe, causing problems trying to click elements on the page.

Would anyone have any suggestions ?

1

Although it takes some work it is possible to make a robust set of tests against the service console. You will need to take some time to build a framework, but once you have this it will make all your tests far easier to write.

The basic formula is to use the JavaScriptExecutor feature of WebDriver to control and find elements from the console by calling the Console Integration Toolkit. The integration toolkit will give you the unique IDs of the parent DIVs that contain the IFrame you will need.

I am writing this code straight into this answer so you may need to tweak any little syntax errors I have :)

To get started you need to load the toolkit into the page:

((JavascriptExecutor)driver).executeScript("

    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '/support/console/37.0/integration.js';    
    document.getElementsByTagName('head')[0].appendChild(script);

");

with the toolkit loaded (and assuming you have a tab open) we can now find the IFrame.

((JavascriptExecutor)driver).executeScript("

    window.selenium = {};

    force.console.getPrimaryTabIds(function(result){
        window.selenium.tabs = JSON.parse(result.ids);
    });

");

You can now retrieve the value of the primary tab IDs and find the element.

Object tabId = ((JavascriptExecutor)driver).executeScript("

    return window.selenium.tabs[0]

");

This will give you the ID of the tab, usually something like scc-pt-0, which you can then use to find the IFrame element using XPath like //div[@id='scc-pt-0']//iframe

| improve this answer | |
  • Thanks very much for the reply. I will try this out and see how I get on and post my results hopefully with success :) – Thomas Woodhouse Jun 24 '16 at 13:06
  • 1
    @ThomasWoodhouse - I hope you had some success with this approach. If the answer helped you can you mark it as accepted so that others can see this. Many thanks! – Mark Keats Jun 29 '16 at 13:37
  • Yep sorry tried this and it works successfully, I just need to implement it correctly into my page Object model So I know that pages of console will always grab the primaryFocused Iframe – Thomas Woodhouse Jun 30 '16 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.