Python Selenium-try except出现无效语法错误
我一直在尝试编写一个Python脚本,该脚本导入并运行Selenium,以模拟浏览器在网页中导航,并且随着相关页面的动态更新(ajax),某些元素将变得可用并被销毁,从而处理Python Selenium-try except出现无效语法错误,python,python-3.x,selenium-webdriver,error-handling,try-catch,Python,Python 3.x,Selenium Webdriver,Error Handling,Try Catch,我一直在尝试编写一个Python脚本,该脚本导入并运行Selenium,以模拟浏览器在网页中导航,并且随着相关页面的动态更新(ajax),某些元素将变得可用并被销毁,从而处理click()或send\u keys()的情况对于不再存在的元素,我正在尝试实现try:except:来处理这个问题-下面是一个代码示例: SuspendedBanner = driver.find_elements_by_class_name('suspended-label ng
click()
或send\u keys()的情况
对于不再存在的元素,我正在尝试实现try:except:
来处理这个问题-下面是一个代码示例:
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
您缺少一个括号。在这里显示的第一行中,有两个左括号,但只有一个右括号
Prices.append(Button.find_elements_by_class_name('bet-button-price')[0].text
#print(Prices)
except:
pass
通常情况下,语法错误消息会指向缺少括号的一行之后的一行(或
]
,等等)。天哪,我真是个白痴!谢谢你指出这一点!它起作用了!我马上就知道了,因为我自己已经做过很多次了。:-)