2016-06-30 7 views
1

나는 명시 적 대기를위한 메소드를 작성했다. 잘못된 로케이터는 내가 잘못된 포기하고 때 나는셀렌 + 파이썬에서 캐치 예외를 찾을 수 없음

여기에 또 다른 방법에서이 메서드를 호출하고

from Page_Objectes import Base_Page 
from Tests.Base_Test_SSA import BaseTest 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.common.exceptions import NoSuchElementException 

class SynchronizationHelper(BaseTest): 

    # def __init__(self, _validate_page): 

    @staticmethod 
    def waitForElementToBeDisplayed(By, locator): 
     wait = WebDriverWait(BaseTest.driver, 60) 
     try: 
      if By == "XPATH": 
       wait.until(EC.presence_of_element_located((By.XPATH), locator)) 
      elif By == "ID": 
       wait.until(EC.presence_of_element_located((By.ID), locator)) 
      elif By == "CSS": 
       wait.until(EC.presence_of_element_located((By.CSS_SELECTOR), locator)) 
     except: 
      NoSuchElementException("Wrong Locator was given") 

을 주어 졌을 때 나는 예외를 잡을 수 없습니까 그러나 xpath 여전히이

을 던지는되지 입니다

NoSuchElementException ("잘못된 로케이터가 지정되었습니다")

답변

0

raise 예외가 필요합니다.

일반 션 :

try: 
    a 
except: 
    print "exception" 
    raise Exception("An exception occured") 

출력 : 단지 raiseexcept 블록 잡힌 같은 예외가 발생한다 하

또한
exception 
Traceback (most recent call last): 
    File "exc.py", line 5, in <module> 
    raise Exception("An exception occured") 
Exception: An exception occured 

.

그림 :

try: 
    a 
except: 
    print "exception" 
    raise 

출력 :

exception 
Traceback (most recent call last): 
    File "exc.py", line 2, in <module> 
    a 
NameError: name 'a' is not defined 
+0

아니, 난 어떤 예외가 발생하지 않았다. 나는 실제로 정적 메서드를 다른 메서드에서 호출하고 있습니다. –

+0

질문을 편집하고 그 방법을 어떻게 부르는 지 보여줄 수 있습니까? – SilentMonk

+0

또한 print 문을'except' 블록에 두어 예외가 있는지 확인하십시오. – SilentMonk

관련 문제