Como navegar para uma nova janela do navegador usando o texto do título parcial usando Python ou JavaScript ou Robot Framework e Selenium

nhrcpt

Durante meus testes, precisamos clicar em links que abrem páginas da web em uma nova guia. Em alguns casos, vemos a falha do teste devido à inclusão de vários caracteres de espaço ou tabulação no texto do título. Um dos exemplos de tais títulos são -

"Looking for more information about US?${SPACE}${SPACE}Find out more from ... Get your questions answered."

Estou tentando mudar para a janela usando o texto parcial "Procurando mais informações sobre os EUA" em vez de usar o texto do título inteiro. Mas até agora não consegui encontrar uma maneira de fazer isso.

Meus códigos atuais são os seguintes:

Test for "Frequently Asked Question"" Link at the bottom panel
    Hide Promo Carousel
    execute javascript  window.scrollTo(0,document.body.scrollHeight)
    Click External Link and Return      partial link:Frequently Asked Questions     Looking for more information about us?  Find out more from ...... Get your questions answered.

e a palavra-chave é:

Click External Link and Return
    [Arguments]     ${Element}  ${ExtUrl}
    ${CurrTitle}=   get title
    click element   ${Element}
    sleep   5s
    run keyword and continue on failure  select window  ${ExtUrl}
    sleep   1s
    run keyword and continue on failure  select window   ${CurrTitle}

Existe uma maneira de localizar e navegar até a janela usando texto parcial do título? Por favor, sugira se existe alguma maneira na estrutura do robô, Python ou JavaScript de fazer isso.

A. Kootstra

Usando o exemplo abaixo, a palavra-chave personalizada usará o navegador atual e, em seguida, use uma pesquisa de padrão para a guia e selecione-a. Se houver mais ou menos de 1 resultado, ele falhará.

*** Settings ***
Library    SeleniumLibrary
Library    Collections

*** Test Cases ***
Select Window Using Partial Title
    Open Browser    http://www.google.com    chrome

    Click Element    link:About    CTRL
    Sleep    5s
    Title Should Be    Google


    Switch Window Using Title Pattern    Over*
    Title Should Be    Over - Google

    [Teardown]    Close Browser

*** Keywords ***


Switch Window Using Title Pattern
    [Arguments]    ${title_pattern}
    ${current_title}    Get Title            # Save the current  tab title
    ${window_titles}    Get Window Titles    # Cycles through the tabs.
    Switch Window       ${current_title}     # Restores the original tab focus

    ${match_count}      Get Match Count    ${window_titles}    ${title_pattern}

    Run Keyword If    '${match_count}'=='0'    Fail    No Browser Tabs found that meet the "${title_pattern}" pattern.
    Run Keyword If    '${match_count}'>'1'    Fail    Too many Browser Tabs found that meet the "${title_pattern}" pattern.

    ${matches}    Get Matches        ${window_titles}    ${title_pattern}   
    Switch Window    ${matches}[0]

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados