Answer a question

Error:

unindent does not match any outer indentation level

Code:

def confirmation(self):
    if WebDriverWait(self.driver, 1000).until(
EC.visibility_of_element_located((By.CLASS_NAME, 'failed'))):
        print("Checkout Failed!")

     if WebDriverWait(self.driver, 1000).until(
EC.visibility_of_element_located((By.CLASS_NAME, 'succesful'))):
        print("Checkout Succesful!")

How can I address the error?

Answers

This error message...

unindent does not match any outer indentation level

...implies that there is a problem with the indentation in your code block.

This error is mostly observed when there is a mixup of Tab and Space characters while indenting Python code.


Analysis

When I copied you code block and executed:

indentation_problem

I got the same error:

C:\Users\username\Desktop\directory\PyPrograms>class_in_python.py
  File "C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\class_in_python.py", line 26
    def confirmation(self):
              ^
IndentationError: unindent does not match any outer indentation level

Once, I removed all the white paces and the new line character and break up the line again for the following line of code, the default indentation seems to be different:

     if WebDriverWait(self.driver, 1000).until(
        EC.visibility_of_element_located((By.CLASS_NAME, 'succesful'))):
        print("Checkout Succesful!")

indentation_difference


Solution

You need to fix up the indentation of the following lines:

  • EC.visibility_of_element_located((By.CLASS_NAME, 'failed'))):
  • EC.visibility_of_element_located((By.CLASS_NAME, 'succesful'))):

You can find a relevant detailed discussion in Is there something issue in indentation, while using Anaconda's Spyder

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐