nhrcpt
nhrcpt

Reputation: 872

Selecting an window using partial url value in Robot Framework or Python

I need to test whether the external links are active and reachable by clicking the elements on the webpage. Below is an example, where we need to click on a link to navigate to panynj.gov. The problem is:

  1. in the html code, the url is coded as href="http://www.panynj.gov/", so missing the security protocol https:
  2. If we click on the link the URL that gets opened is "https://www.panynj.gov/port-authority/en/index.html"

Since the newly opened URL does not match the original href value, my script is unable to select the newly opened tab.

I am looking for a solution that can either:

  1. Select the newly opened tab using partial URL text. As an example, I can trim the http:// from the href value and use the "www.panynj.gov" to select the newly opened tab, Or
  2. I can select the last opened Tab (which should be technically the one that opened after the click action on the element) from all the tabs and run checks.

My codes are as follows:

*** Test Cases ***

Test for Selecting Tab using partial URL
   go to                ${HomePage}
   Click Element        xpath://*[@href="http://www.panynj.gov/"]   
   Test Navigation to unsecured url     http://www.panynj.gov/      ${HomepageTitle}


*** Keywords ***

Test Navigation to unsecured url
    [Arguments]     ${href}     ${Title_}
    ${str} =   Replace String   ${href}    http    https
    select window    url:${str}
    ${location}     get location
    run keyword if  "${Location}"=="${str}"    close window
    select window    ${Title_}

Upvotes: 1

Views: 510

Answers (1)

nhrcpt
nhrcpt

Reputation: 872

Following the answer in How to navigate to new browser window using partial title text using either Python, or JavaScript or Robot Framework and Selenium by A Kootstra I was successfully able to resolve my problem and navigate using partial URL text.

Upvotes: 1

Related Questions