wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 255 forks source link

Interacting with iframe doesn't work using switch_to.frame with ChromeDriver #150

Closed GiuT closed 4 years ago

GiuT commented 4 years ago
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import time

url = 'https://sahkovertailu.fi/'
options = {
    'suppress_connection_errors': False,
    'connection_timeout': None# Show full tracebacks for any connection errors
}
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--auto-open-devtools-for-tabs')
chrome_options.add_argument('--log-level=2')

driver = webdriver.Chrome(ChromeDriverManager().install(), seleniumwire_options=options, chrome_options=chrome_options)

if driver.requests is not None:
    del driver.requests
driver.get(url)

iframe = driver.find_element_by_xpath("//iframe[contains(@src, 'privacy')]")
driver.switch_to.frame(iframe)
button = driver.find_element_by_xpath("//button[contains(., 'OK')]")
button.click()

Above code showcases the issue - it should close the cookie consent modal by clicking OK, however this does not work. Using firefox with from webdriver_manager.firefox import GeckoDriverManager however works.

GiuT commented 4 years ago

Not so sure this is related to selenium-wire after all, as removing the argument --auto-open-devtools-for-tabs fixed the issue with Chrome.