Python and Selenium: Syntaxerror: invalid syntax

Asked

Viewed 502 times

0

I am trying to log automatically on facebook with the code below,

   from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    import unittest

class LoginTest (unittest.Testcase):

    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("https://facebook.com.br")

    def test_Login(self):
        driver = self.driver
        facebookUserName  = "[email protected]"
        faceboookPassword = "mypassword"

        #emailfFieldId    = "email"
        emailFieldID = ".//*[@id='email']"
        #passFieldId      = "pass"
        passFieldID = ".//*[@id='pass']"
        loginButtonXpath = "//input[@value='Log In']"
        fbLogoXpath      = "(//a[contains(@href, 'logo')])[1]"


        emailFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(emailFieldID))
        passFieldElement  = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(passFieldID))
        loginButtoElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath)

        emailFieldElement.click()
        emailFieldElement.clear()
        emailFieldElement.send_keys(facebookUserName))

        passFieldElement.click()
        passFieldElement.clear()
        passFieldElement.send_keys(faceboookPassword)
        loginButtoElement.click()

        WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

the error that cmd returns to me.

  File "facebooklogin.py", line 29
    emailFieldElement.click()
                    ^
SyntaxError: invalid syntax

1 answer

3


Whenever you see that the problem is in a row look also in the previous lines, usually errors of Parser (Syntactic analysis) may be in these lines above, in your case the problem is here:

loginButtoElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath)

What’s right is this:

loginButtoElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath))

There was one more ) in the end.

  • 1

    Great, thanks for the tip !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.