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
saximi
V2EX  ›  Python

请教关于 selenium 中 expected_conditions 的问题

  •  
  •   saximi · 2017-10-09 22:45:51 +08:00 · 1804 次点击
    这是一个创建于 2389 天前的主题,其中的信息可能已经有所发展或是发生改变。
    程序 1: 
    WebDriverWait(driver,10).until(expected_conditions.find_element_by_xpath(某路径)) 
    
    程序 2: 
    driver.implicitly_wait(10)  
    driver.find_element_by_xpath(某路径) 
    
    请问,上面程序 1 和程序 2 实现的功能是否是相同的,都是等待某个操作完成,但等待时间最长不超过 10 秒? 
    我理解应该实现的功能是相同的,区别在于程序 1 需要对于每一个操作都调用 expected_conditions,但是程序 2 只要写一次 implicitly_wait 语句,就可以对整个程序文件中的操作都实现同样的效果,是这样么? 
    感谢指点! 
    
    1 条回复    2017-10-09 23:21:39 +08:00
    mlyy
        1
    mlyy  
       2017-10-09 23:21:39 +08:00 via iPhone
    python 有个模块叫 logging,看看文档你就可以打开 DEBUG 级别的输出,然后你就能在控制台看到 selenium 和浏览器交互的完整过程,然后你就知道上面两种方法的阻塞原理了。简单来说,方法一是轮询的实现,而方法二是线程休眠的实现。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2667 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:03 · PVG 08:03 · LAX 17:03 · JFK 20:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.