无法看到Selenium异常错误消息

时间:2018-06-01 15:46:33

标签: python selenium selenium-webdriver

我将Try / Except子句添加到我的Selenium脚本中,但是当我在PyCharm中执行此操作时,我很难看到错误消息。脚本爆炸但没有发现错误。

我故意改变了XPATH,所以它会失败,我尝试了几种方法,但这两种方法都没有实际将错误信息打印到屏幕上。有什么想法吗?

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException

def choose_dress(self):
        try:
            self.dresses = WebDriverWait(self.driver.instance, 5).until(
            EC.visibility_of_element_located((
                By.XPATH, '//*[@id="block_top_menu"]/ul/li[2]/b')))
        except NoSuchElementException:
            pass
        else:
            print('NO ELEMENT FOUND!')


def choose_dress(self):
    try:
        self.dresses = WebDriverWait(self.driver.instance, 5).until(
        EC.visibility_of_element_located((
            By.XPATH, '//*[@id="block_top_menu"]/ul/li[2]/b')))
    except NoSuchElementException:
        print('NO ELEMENT FOUND!')
    else:
        self.dresses.click()

0 个答案:

没有答案