V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

pycharm 调试的时候遇到一个比较奇怪的问题

  •  
  •   woshichuanqilz · 2018-09-28 09:43:08 +08:00 · 6642 次点击
    这是一个创建于 2009 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def ElementOperate(driver, elem_name, this_op_dict, dynamic_data_dict=dict(), no_print=False):
       wait_time = 20
       elem = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_xpath(xpath))  # 在这行设置条件断点 elem_name = 'xxx' 报错
    

    使用的是 pycharm

    elem = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_xpath(xpath)) # 在这行设置条件断点 elem_name = 'xxx' 报错

    错误信息:

    Connected to pydev debugger (build 182.4323.49)

    Error while evaluating expression: elem_name == 'search_result_item'

    Traceback (most recent call last):

    File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.3\helpers\pydev_pydevd_bundle\pydevd_frame.py", line 43, in handle_breakpoint_condition

    return eval(condition, new_frame.f_globals, new_frame.f_locals)

    File "<string>", line 1, in <module></module></string>

    NameError: name 'elem_name' is not defined

    Backend Qt5Agg is interactive backend. Turning interactive mode on.

    1. 排除几个因素, 这个错误应该是在 pycharm 的 debug 预处理类似的时候出现的问题, 问题是在程序运行开始之前发生的

    2. 如果把: elem = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_xpath(xpath)) 换成一个简单的 print('xxx')则问题不会出现.

    3. 把: elem = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_xpath(xpath)) 换成: elem = WebDriverWait(driver, 20)问题也不会出现。。。

    请问这个是什么问题?有哪位高手了解这个 pycharm 调试机制是什么? 如何解释这个错误?

    6 条回复    2018-09-28 11:51:50 +08:00
    sangleft
        1
    sangleft  
       2018-09-28 09:50:26 +08:00 via Android
    双等号??
    xpresslink
        2
    xpresslink  
       2018-09-28 10:12:05 +08:00
    别写得这么孟浪 把 lambda driver : driver.find_element_by_xpath(xpath) 改写成一个 普通 def 函数,把函数名放这儿 试一下。
    woshichuanqilz
        3
    woshichuanqilz  
    OP
       2018-09-28 10:20:28 +08:00
    @sangleft
    主题里面有笔误,
    # 在这行设置条件断点 elem_name = 'xxx' 报错
    ---> elem_name == 'xxx'

    实际代码里面这个条件是对的。
    neoblackcap
        4
    neoblackcap  
       2018-09-28 10:27:43 +08:00
    @woshichuanqilz 你将断点设置在 elem_name 赋值之后的下一行试试
    sangleft
        5
    sangleft  
       2018-09-28 11:20:16 +08:00 via Android
    @woshichuanqilz 理解了…
    woshichuanqilz
        6
    woshichuanqilz  
    OP
       2018-09-28 11:51:50 +08:00
    @neoblackcap elem_name 是传进来的参数, 这个错误不是在正常时候执行发生的问题, 是程序还没有运行的时候, 似乎是在预处理到这个位置的时候报错的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3861 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 05:08 · PVG 13:08 · LAX 22:08 · JFK 01:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.