hallopeterswelt
hallopeterswelt

Reputation: 53

Change to iframe in selenium

https://www.gmx.net

I want to click on Zustimmen und weiter.

driver.get('https://www.gmx.net')
WebDriverWait(driver, 10).until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, '/html/body/iframe')))
driver.find_element_by_xpath('//*[@id="save-all-conditionally"]').click()

The code above is not working for me.

enter image description here

Upvotes: 1

Views: 44

Answers (1)

Prophet
Prophet

Reputation: 33353

Element you are trying to access is located inside nested iframe, one iframe insde another iframe.
You should switch to the first iframe, then to the inner iframe and then to click the "Get cookies" button.
This should work:

wait = WebDriverWait(driver, 20)
wait.until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[@class="permission-core-iframe"]')))
wait.until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@src,'plus')]")))
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="save-all-conditionally"]'))).click()

When you finished working inside that iframe you will have to switch to the default context with

driver.switch_to.default_content()

Upvotes: 1

Related Questions