Python Selenium - Invalid syntax error with try except

Jeremy

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
Deepstop

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related