I'my trying to apply an if / else statement in Python to know if I have an element or not and if it is the case, click on it. But I don't know why I have a syntax error and I don't see where I have made a mistake.

This is the part of my code concerned by this issue:

if driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/button[2]"):
        print "Oh this conversation already exists !"
        print "No conflict!

When I launch my script, I have the following syntax error:

>  File "group_discussion_script.py", line 51    print "Oh this
> conversation already exists !
>        ^ syntaxError: invalid syntax

I wonder if this line is really tolerated?


Any idea whats wrong?

1 Answer 1


Fixed, I have simply forgot to close the parenthesis:

  • 2
    It is better to use relative xpath expression than absolute xpath expression.
    – Yu Zhang
    Oct 14, 2016 at 9:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.