How to use Switch Page

Hi, I’ve just started using Browser Library and have been searching for an answer to my problem without success.

I’ll try to explain below and have included my script in the end of the post.

  1. I open a new page and navigate to a form which is filled in.
  2. Once that form is saved I click on a button to enable a link (different URL each time it’s generated) which is clicked and should be opened in a new page.
  3. But how do I follow that link? As I understand I should be able to do that with Switch Page and an Id, but the Id is regenerated each time.

Create and delete simulator container
[Tags] browser
New Page http://172.16.0.242:9999/main.html
Click id=containerNav
Click id=containerCreateButton
Fill Text id=containerEditDescription AutomatorVSP
Select Options By id=containerEditOwner text Fredrik
Select Options By id=containerEditCurrency value EUR
Select Options By id=containerEditCrType value CR2
Select Options By id=containerEditLanguage value en
Select Options By id=containerEditLibSetup value Refilled
Check Checkbox id=containerEditResetOnStart
Click id=editContainerDialogSaveButton
Browser.Get Text xpath=//*[@id=“containerTable”]/tbody/tr[1]/td[1] == AutomatorVSP
Click id=startButton10033
Wait For Elements State id=wvspButton10033 enabled timeout=30s
Click id=wvspButton10033
Switch Page
Take Screenshot

Hi Fredrik,

i think I under stand your issue, I’ve made a small modification to your test which might do what your after.

Create and delete simulator container
    [Tags]  browser
    New Page     http://172.16.0.242:9999/main.html
    Click     id=containerNav
    Click     id=containerCreateButton
    Fill Text     id=containerEditDescription     AutomatorVSP
    Select Options By     id=containerEditOwner     text     Fredrik
    Select Options By     id=containerEditCurrency     value     EUR
    Select Options By     id=containerEditCrType     value     CR2
    Select Options By     id=containerEditLanguage     value     en
    Select Options By     id=containerEditLibSetup     value     Refilled
    Check Checkbox     id=containerEditResetOnStart
    Click     id=editContainerDialogSaveButton
    #
    # I'm guessing here is where you retrieve the dynamic button id?
    #     when you use Get Text, you will probably want to save the result to a variable
    #     see link to Get Text doco below
    #
    ${btnId}=    Get Text     xpath=//*[@id=“containerTable”]/tbody/tr[1]/td[1] == AutomatorVSP
    Click     id=${btnId}
    Wait For Elements State     id=${btnId}     enabled     timeout=30s
    Click     id=${btnId}
    # when using Switch Page you need to specify which page you want to switch to
    #     see link to Switch Page doco below
    # When we switch to the new browser tab we can save a reference to the page we started on so we can go back to it if we want. (this is optional)
    ${previous_page}=    Switch Page    NEW
    Take Screenshot
    # go back to the original page
    Switch Page    ${previous_page}

While this may not work exactly it should give you the idea what you need and with some tweaking you should be able to get it working.

Dave.