【问题标题】:How to acces a iframe whitout src SELENIUM如何在没有 src SELENIUM 的情况下访问 iframe
【发布时间】:2021-06-06 21:54:42
【问题描述】:

我试图切换到框架,但如果我使用:

self.__driver.switch_to.frame(self.__driver.find_element_by_tag_name('iframe'))

我得到一个 iframe empy,但我无法访问框架内的输入。

如果我使用这个:

WebDriverWait(self.__driver, 30).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'pp-EY0PvP-44')))

我收到了这个错误:

selenium.common.exceptions.NoSuchElementException: 消息:没有这样的 元素:无法定位元素

这是html: HTML image link

【问题讨论】:

标签: selenium web-scraping


【解决方案1】:

就我所关心的 Selenium 文档而言,您也可以使用 iframe 的“id”。

【讨论】:

  • 我无法访问 id,我得到 selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element
  • 该 ID 可能不稳定。或者可能涉及另一个 iframe 或时间问题?我们需要查看更多您的代码和 html。
【解决方案2】:

使用WebDriverWait 切换到iframe,如下所示:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@name, 'ApxSecureIframe-pp-')]")))

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多