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]"):
driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/button[2]".click()
print "Oh this conversation already exists !"
else:
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?
driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/button[2]".click()
Any idea whats wrong?
1 Answer 1
Fixed, I have simply forgot to close the parenthesis:
driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/button[2]").click()
HERE^
-
2It is better to use relative xpath expression than absolute xpath expression.Yu Zhang– Yu Zhang2016年10月14日 09:00:04 +00:00Commented Oct 14, 2016 at 9:00