0

im trying to loop a text while input text but i got some error when running it

  *** Settings ***
 Library  Selenium2Library          

  *** Variables ***       

${URL}  https://www.ebay.com           
${Browser}  Chrome   
${Searching}  xpath=//input[@id='gh-ac']    
${Name}  book


 *** Test Cases ***    

Test case Register Positive    
  Open Browser    ${URL}  ${Browser}    
  Input Text  ${Searching}  ${Name}    
  FOR  ${Index}  IN   0   100        
  #LOG TO CONSOLE    ${i}    
    Run Keyword If  ${Searching}  ==  'CONTINUE'   Continue For Loop    
  END

Error says Evaluating expression 'xpath=//input[@id='gh-ac']' failed: SyntaxError: invalid syntax (, line 1)

Please Help

2
  • try: xpath=//*input[@id='gh-ac'] Commented Oct 19, 2019 at 21:00
  • @Krzy: no, that's not the problem. Commented Oct 19, 2019 at 22:18

1 Answer 1

1

When robot translates your statement to python code in order to evaluate the expression, it looks literally like this to the python interpreter

if xpath=//input[@id='gh-ac']:

That is invalid python syntax, so you get the error.

If you want to use that variable in a conditional statement, the best solution is to use the special syntax where you omit the braces. When you do that, the variable is used as-is rather than being converted to a string before being handed to python.

You also need to have no more than a single space on each side of ==:

Run Keyword If  $Searching == 'CONTINUE'   Continue For Loop 

For more information in this syntax see Evaluating Expressions in the documentation for the built-in library.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.