无法访问 Iframe

Lea*_*ion 0 python iframe selenium

在此输入图像描述在此输入图像描述这是我的 HTML:

<iframe id="3093bab4-296d-4f37-8041-ce4f78358f44" frameborder="0" width="100%" height="100%" allowtransparency="true" src="http://gksdc-tst.pvhcorp.com:50100/pvh-pos-server/functions#functionId=S.01100202304.00&amp;reqId=2b5b69f9-1f44-4c5d-9313-b6cc5d570f5e" cd_frame_id_="bcd064222ffff8919b77d7a162b6e1fe"></iframe>
Run Code Online (Sandbox Code Playgroud)

我实际上试图单击此框架下的一个按钮“发布”,但出现以下异常:

Traceback (most recent call last):
  File "C:\Users\kenaik\PycharmProjects\gksdc-tst.pvhcorp.com\Package_1\CashManagement.py", line 119, in <module>
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "iframe[src*='http://gksdc-tst.pvhcorp.com:50100/pvh-pos-server/functions']']")))
  File "C:\Users\kenaik\PycharmProjects\gksdc-tst.pvhcorp.com\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试的:

wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "iframe[src*='http://gksdc-tst.pvhcorp.com:50100/pvh-pos-server/functions']']")))
wait.until(EC.element_to_be_clickable(By.XPATH,"//span[contains(text(),'Post')]")).click()
Run Code Online (Sandbox Code Playgroud)

谁能告诉我,出了什么问题吗?谢谢

cru*_*dey 5

css_selector不是xpath

尝试这个 :

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src*='http://gksdc-tst.pvhcorp.com:50100/pvh-pos-server/functions']']")))
Run Code Online (Sandbox Code Playgroud)

还要确保在此之前您不在任何 iframe 中,如果是,您应该切换到如下默认内容:

driver.switch_to.default_content()
Run Code Online (Sandbox Code Playgroud)