I would like to automate a log in process in Robotframework. Unfortunately I don't know that the current user has a soft token or not. If the user doesn't have any, will get an SMS immediately. If the user has one or more soft tokens, he/she has to click on a link, to get the SMS.
The process: the login process
The code:
Input Text ${userNameField} ${User}
Click element ${nextButton}
${present}= Run Keyword And Return Status Element Should Be Visible ${getSMSCodeButton}
Run Keyword If ${present} Click element ${getSMSCodeButton}
Wait Until Element Is Visible ${passwordField}
Input Text ${passwordField} Password1
The main problem, after I click on the next button, the ${present} variable will be always False, because the next page doesn't loaded yet. If I add some implicit wait (3 sec) after "Click element ${nextButton}", the code works like charm, but I don't want to use the Sleep keyword, rather I would like to wait for to load the page fully.
How should I solve it, with explicit wait?
CodePudding user response:
You can control better the implicit wait and timeouts when importing the library. See the section Importing.
But by replacing Element Should Be Visible
by [Wait Until Element is Visible][2]
you will get what you need. Below is you test code, using new recommended IF
:
*** Settings ***
Library SeleniumLibrary 15 5
(...)
Input Text ${userNameField} ${User}
Click element ${nextButton}
${present}= Run Keyword And Return Status Wait Until Element Is Visible
${getSMSCodeButton}
IF ${present}
Click Element ${getSMSCodeButton}
END
Wait Until Element Is Visible ${passwordField}
Input Text ${passwordField} Password1
CodePudding user response:
There is alternate kw present too, try to use Waits until the element locator appears on the current page.
Wait Until Page Contains Element <locator>