1
votes

In Robotframework, the 'Click Button' keyword do clicks the button, but when it comes to check that the button doesn't exist anymore and it's clicked, sometimes additional check ( like Page Should Not Contain or Element Should Not Be Visible ) Is fails or the script can't find the button to click it.

What I have tried:

  1. For loop to click button- Code below
  2. Wait Until Keyword - Code below
  3. Click element using Javascript

Issue is intermittant fails 1 of 5 times.How can I deal with this Problem?

//Code Samples 2 different ways to click the button

  1.
       Wait Until Page Contains Element ${BTN_BET} 60s
       Double Click Element ${BTN_BET}
       FOR ${INDEX} IN RANGE 100
       ${CHECK}= Run Keyword And Return Status Page Should Contain Element ${BTN_BET}
       Run Keyword If '${CHECK}' == "True" Double Click Element ${BTN_BET}
       Run Keyword If '${CHECK}' == "False" Exit For Loop
       END
       Page Should Contain
      ... You clicked the button

  2.

    Wait Until Keyword Succeeds 60s 0.5s Page Should Contain Element ${BTN_BET}
    Sleep 2s
    Wait Until Keyword Succeeds 30s 0.5s Execute JavaScript document.evaluate             
    ('${BTN_BET}',document.body,null,9,null).singleNodeValue.click()
    Sleep 5s
    Wait Until Page Contains Element //div[@class='results-warning' and .='Wait 
    for another stage'] 40s
    Page Should Contain
    ... You clicked the button
1
show how the element html looks like. don't add the screenshot of the html codeDev
<button class="bidder-btn">make a bet</button>Vladyslav Koval

1 Answers

1
votes

So, I found out good decision that resolves my problem. I rewrote the FOR loop in that way

FOR ${INDEX} IN RANGE 20
    ${BET_BUTTON_NOT_PRESSED} = Run Keyword And Return Status Page Should Contain Element ${BTN_BET}
    Run Keyword If '${BET_BUTTON_NOT_PRESSED}' == "True" Click Button ${BTN_BET}
    Sleep 1s
    Continue For Loop If ${BET_BUTTON_NOT_PRESSED} == "False"
END

The problem was in the button, it did not disappear immediately, but when I added 'Sleep 1s' in my loop - 10 of 10 tries was passed. I think that the problem itself is javascript is loading too slow.