Selenium's frame_to_be_available_and_switch_to_it() doesn't seem to be waiting long enough in Python.
When I run the code with the commented line for the program to sleep I can find my dates, however when it is commented my dates are not found since I don't switch to the iframe ( or that's what I think). It seems to me that frame_to_be_available_and_switch_to_it() isn't waiting long enough or isn't working. Since the wait time is set to be longer (3 < 10) I'm guessing it isn't working. I'm new to selenium though so I may be misunderstanding something.
Any suggestions?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re
import time
driver = webdriver.Chrome(r'/mypath/chromedriver.exe')
driver.get(file_name)
dates = []
try:
# Click the iframe
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.ID, "myid"))).click()
try:
# find the iframe
#time.sleep(3)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "myxpath")))
# Find the date sources
soup = driver.page_source
dates = re.findall(r'myexpression', soup, re.S)
except:
print("--------------iframe not found-------------------");
except:
print("--------------click did not work-------------------");
In brief: I tried to force the program to wait and I found that it works and so I'm wondering why the function doesn't wait itself.