selenium.common.exceptions.NoSuchWindowException:消息:使用 Selenium 和 Python 在 iframe 中单击元素时没有此类窗口错误

2022-01-10 00:00:00 python selenium xpath css-selectors iframe

问题描述

我从 Selenium 开始并有一个问题,基本上我不明白为什么当我切换到 iframe 并选择我经常得到的元素之一时:

I'm starting with Selenium and have a question, basically I don't understand why when I switch to an iframe and select one of the elements I constantly get:

selenium.common.exceptions.NoSuchWindowException: Message: no such window
  (Session info: chrome=84.0.4147.89)

这是相关代码,首先我单击包含 iframe 的 DOM 的某些元素,该元素实际上更新 iframe 内容,然后选择 iframe,切换到它,然后在 iframe 的 HTML 内容中选择我想要的元素

This is the relevan code, firstly I click on some element of the DOM containing the iframe that actually updates the iframe content and then select the iframe, switch to it and then select the element I want inside the HTML content of the iframe

# Select the item on main DOM that will udpate the iframe contents
bandeja = driver.find_element_by_xpath("//*[@id='sm20']")
bandeja.click()
# Tried sleeping, but also WedDriverWait to no avails...
time.sleep(3)
# Get the frame that actually has the content
frame = driver.find_element(by=By.NAME, value="ifrInterior")
driver.switch_to.frame(frame)
# Select the element inside the iframe and click
equipo = driver.find_element_by_xpath("//input[@name='gestionesPropias_Equipo']")
equipo.click()

现在如果我调试它,我没有收到上面的错误,我可以看到那里的元素已被选中...但点击后没有任何反应

Now if I debug this, I don't get the error above, and I can see there element has been selected...but upon click nothing happens

这是预期的元素,甚至检查了base64中的屏幕截图,它看起来还不错,它是一个单选输入按钮......只是想知道为什么点击不起作用??

This is the expected element, even checked the screenshot in base64 and it looks ok, it's a radio input button...just wondering why click doesn't work??

更新:根据@DebanjanB 的回复,我使用了他的建议,这可行,但按钮没有被点击

UPDATE: Based on response from @DebanjanB I used his sugestion and this works but the button does not get clicked

点击后应该会启用一个新的下拉菜单

Upon clicking there should a new drop down be enabled

这是单选按钮:

点击此下拉菜单时启用:

When clicked this drop-down is enabled:

该元素的相关代码

<span id="filtroAsignado" class="W30">
            
    <select name="nuumaAsignado" class="W84">       
        <option value="">[Todo mi equipo]</option></select>
            
</span>

所以现在我想知道为什么它没有被点击?

So now I wonder why this does not get clicked?


解决方案

由于所需元素位于