ElementClickInterceptedException:消息:元素 <select id 因为另一个元素 <iframe id="ba-widget-iframe" 遮挡了它

ElementClickInterceptedException: Message: Element <select id because another element <iframe id="ba-widget-iframe" obscures it

我有一个下拉单 select 组合框。 我可以通过 CSS select 或

获得对该下拉菜单的引用
<select class="single-option-selector no-select selector single-option-selector-100" data-option="option1" id="product-select-template--15646112383191__main-option-0">
    <option value="15.0cm">15.0cm</option>
    <option value="23.0cm">23.0cm</option>
    <option value="25.0cm">25.0cm</option>
</select>

我试过了

drop_down = [item.web_element for item in find_all(S(".single-option-selector-100"))][0]
select(drop_down, "23.0cm")

而我运行进入异常

    ElementClickInterceptedException: Message: Element 
<select id="product-select-template--15646112383191__main-option-0" 
class="single-option-selector no-select selector single-option-selector-100"> 
is not clickable at point (1012,655) because 
another element <iframe id="ba-widget-iframe" src="about:blank"> 
obscures it

关于如何克服这个问题有什么想法吗?

你好 非常感谢大家的帮助和支持。 在你们为此奋斗了 2 天多的时间里,我得到了很多指导,得以解决这个问题。 这是一个工作代码。

driver = start_firefox(headless=False)                                                                                                                                  
go_to(url)                                                                                                                                                                     
click(Button("Allow All"))  #Need this to accept all cookies                                                                                                   
frame = driver.find_element_by_xpath("//iframe[@id='ba-widget-iframe']")                                                        
driver.switch_to.frame(frame) #need to switch to iframe thingy.                                                                           
driver.find_element_by_css_selector("path").click()  #makes the iframe Modal go away phew finally      
driver.switch_to.parent_frame()  #Now iframe is finally done and dusted go back to main window and do actual meaningful work                               
drop_down = [                                                                                        
    item.web_element                                                                                 
    for item in find_all(                                                                            
        S(".single-option-selector.no-select.selector.single-option-selector-100")                     
    )                                                                                                
][0]                                                                         
select(drop_down, "23.0cm")

                                                                                              
                                                                              
                                                                                                             

                                                             

非常感谢所有的帮助:)

首先你必须切换到iframe;

iframe = driver.find_element_by_xpath("//iframe[@id='ba-widget-iframe']")
driver.switch_to.frame(iframe)
drop_down = [item.web_element for item in find_all(S(".single-option-selector-100"))][0]
select(drop_down, "23.0cm")

我认为您仍然收到 same/exact 错误,因为下拉菜单选择不正确。你可以试试这个。

frame = driver.find_element_by_xpath("//iframe[@id='ba-widget-iframe']")
driver.switch_to.frame(iframe)


Select(WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, "//select[@class='single-option-selector no-select selector single-option-selector-100']")))).select_by_value("15.0cm")


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

我建议相同,切换到 iframe,并检查同步。您可以尝试使用 selenium ide 记录场景,并导出代码以查看是否有帮助。