0

I've been trying to put together a Python script which imports and runs Selenium to simulate a browser navigating through a webpage and, as the page in question dynamically updates (ajax), certain elements will become available and be destroyed so, to handle cases where click() or send_keys() to elements which no longer exists, I'm trying implement try: except: to handle this - A sample of the code is below:

                    SuspendedBanner = driver.find_elements_by_class_name('suspended-label ng-scope')
                    CheckInPlay = driver.find_elements_by_class_name('market-status-label')
                    if len(SuspendedBanner) == 0 and CheckInPlay(0).text == 'In-Play':
                        try:
                            driver.find_elements_by_class_name('rh-back-all-label ng-binding')(0).click()
                            PriceInputs = driver.find_elements_by_class_name('find_elements_by_class_name')
                            if len(PriceInputs) > 4:
                                for PriceInput in PriceInputs:
                                    PriceInput.send_keys('1.01')
                                    BackButtons = driver.find_elements_by_class_name('back mv-bet-button back-button back-selection-button')
                                    if len(BackButtons) == Len(PriceInputs):
                                        for Button in BackButtons:
                                            Prices.append(Button.find_elements_by_class_name('bet-button-price')[0].text
                                        #print(Prices)
                        except:
                            pass

1 Answer 1

1

You are missing a parenthesis. In the first line shown here there are two opening parentheses but only one closing parenthesis.

Prices.append(Button.find_elements_by_class_name('bet-button-price')[0].text
                                        #print(Prices)
                        except:
                            pass

It is often the case that the syntax error message will point to a line after the one with the missing parenthesis (or ], etc).

2
  • My god, I'm such an idiot! Thanks for pointing that out! It works!
    – Jeremy
    Commented Jul 31, 2019 at 18:25
  • I knew right away because I've done it so many times myself. :-)
    – Deepstop
    Commented Jul 31, 2019 at 18:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.