尽管切换到iframe也无法点击元素

时间:2020-10-19 13:39:35

标签: python selenium iframe selenium-chromedriver

我无法点击此元素GMX mail privacy popup

选择按钮ID 'onetrust-accept-btn-handler'不起作用,xpath也不起作用。

我只能从4个iframe中选择一个,而它似乎并不是正确的。

这是我当前的代码。我试图使用javascript单击该按钮,但还是没有用。

url = 'https://www.gmx.co.uk/'

chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(
    executable_path=r'.\chromedriver.exe', options=chrome_options)

driver.get(url)


#this counts the iframes, and even though the output says '1', their are 3 others I selenium interact with.

time.sleep(5)
seq = driver.find_elements_by_tag_name('iframe')
print("Number of frames present in the web page are: ", len(seq))

iframe = WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.TAG_NAME, 'iframe')))
driver.switch_to.frame(iframe)

element = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '/html/body/div/div[3]/div/div/div[2]/div/div/button')))
element.click() 
driver.execute_script("arguments[0].click();", element)

但是我几乎立即得到selenium.common.exceptions.TimeoutException,而不是ElementNotInteractableExceptionNoSuchElementException.

0 个答案:

没有答案