推荐学习书目
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
cool1205
V2EX  ›  Python

技术求助: selenium 、driver.switch_to.window,切换至新标签页后获取元素需要两秒

  •  
  •   cool1205 · Nov 21, 2020 · 2579 views
    This topic created in 2004 days ago, the information mentioned may be changed or developed.
    各位大佬好,小弟最近遇到一个 python 技术问题,我用 selenium 测试网页,正常操作都没问题,页面有一个功能是使用 showModelessDialog,不过我切换至 win.open 可以正常打开并且获取到新页面中的元素,但切换至新页面后,切换基本上不用时间,获取第一个元素需要两秒的时间,多次尝试都是两秒,后续获取元素是非常快,我的这个页面是提前已经加载好了的,应该不存在元素还没有加载出来的情况,我想问有没有什么办法可以把这两秒的时间给去掉?

    我尝试使用 WebDriverWait(self.driver, 5, poll_frequency=0.2, ignored_exceptions=None).until(EC.presence_of_element_located((By.NAME, "xxx")))这个语句,但没效果

    如下是我输出的日志:
    2020-11-21 13:56:23.394 切换窗口时间:9
    2020-11-21 13:56:23.420 找第一个元素时间:2060
    2020-11-21 13:56:23.429 找第二个元素时间:8
    3 replies    2020-11-22 10:47:15 +08:00
    saulshao
        1
    saulshao  
       Nov 21, 2020
    从你的描述来看,就是没加载完成,你这个页面有些什么脚本吗?
    sa2501
        2
    sa2501  
       Nov 22, 2020
    差不多就行了,都用 seleniu 测上前台页面了,还在乎这 2 秒
    cool1205
        3
    cool1205  
    OP
       Nov 22, 2020
    如何没办法解决,有哪位大佬知道是什么原因造成的吗?没加载出来我觉得不可能,毕竟这个页面已经打开十几秒了,并且每次找第一个元素的时间惊人的一致
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1683 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    ♥ Do have faith in what you're doing.