【问题标题】:Selenium chromedriver simply does not detect certain websites or their elementsSelenium chromedriver 根本无法检测某些网站或其元素
【发布时间】:2020-10-30 02:07:32
【问题描述】:

编写的通过chromedriver与某个网站交互的python脚本找不到任何元素或打印页面源。整个页面位于框架集中的框架内。似乎切换到框架是人们在这种情况下给出的建议。我无法找到带有标签名称或 XPath 的框架

网站的一般 HTML

<html>
    <head>
    </head>
           <frameset>
                    <frame src="ebrokerlogin.html">
                          <html>
                               rest of website !!!!!!!!!      
                          /html>
                     </frame>
           </frameset>
</html>

一旦页面打开,这些行就会运行

driver.switch_to.frame(driver.find_element_by_tag_name("frame"))
print(driver.page_source)

我收到的异常是

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"frame"}
  (Session info: chrome=83.0.4103.116)

如何切换到网站上的框架?为什么我的方法不起作用?

evidence of tag name

ps:如果我注释掉driver.switch_to,打印出来的页面源是上一个网站,不是这个。

更新:XPath 也不起作用的证据 evidence of xpath

【问题讨论】:

  • 当您尝试通过 xpath 定位元素时会发生什么?您是否尝试过等待页面加载?
  • 同样的病添加更多的证据表明,是的,隐含和 time.sleep(10)
  • 如果 driver.page_source 在您切换到框架之前打印出不同网站的 html,则您可能根本没有切换页面。在切换框架之前尝试打印当前 url。如果这是错误的,请确保在尝试切换到框架之前切换 url
  • jd 鲁迪。你是对的谢谢你

标签: python html selenium selenium-chromedriver frame


【解决方案1】:

selenium 通过点击链接获得了这个网站。它似乎继续相信它在以前的网站上

【讨论】:

    猜你喜欢
    • 2021-05-18
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 2021-10-05
    相关资源
    最近更新 更多