V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Oct 9, 2017 · 2341 views
    This topic created in 3127 days ago, the information mentioned may be changed or developed.
    程序 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 replies    2017-10-09 23:21:39 +08:00
    mlyy
        1
    mlyy  
       Oct 9, 2017 via iPhone
    python 有个模块叫 logging,看看文档你就可以打开 DEBUG 级别的输出,然后你就能在控制台看到 selenium 和浏览器交互的完整过程,然后你就知道上面两种方法的阻塞原理了。简单来说,方法一是轮询的实现,而方法二是线程休眠的实现。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   762 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:17 · PVG 05:17 · LAX 14:17 · JFK 17:17
    ♥ Do have faith in what you're doing.