Python selenium "Explicit waits" for a frame
On the same page, the same step if using "wait" will get the error "NoSuchElementException: Message: Unable to find element named == rw"
if using "switch_to_frame" will result in a successful frame switch.
why are there different?
1)
wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_name('rw')))
2)
driver.switch_to_frame('rw')
3)
class cm(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Ie()
self.driver.implicitly_wait(30)
self.base_url = "http://mytestweb.com"
def testcm(self):
driver = self.driver
driver.maximize_window()
self.driver.get(self.base_url)
wait = WebDriverWait(driver, 30)
self.main_wh = driver.window_handles
## wait.until(EC.invisibility_of_element_located((By.ID,'Frame2')))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,'rw')))
## driver.switch_to_frame('rw')
if i tried to use 3) you get a timeout message
+3
source to share
1 answer
Chances are the item named rw, which actually takes a while to load, is not loading properly before the lookup occurs. Basically, you are looking for the same element before the expected condition takes effect. The best implementation would be as follows:
wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,'rw')))
See doc
+1
source to share