User8392 User8392 - 2 months ago 8
Python Question

How to identify and switch to the frame source in Selenium?

I have been using the Selenium and Python2.7, on Firefox.

I would like it to work like the following, but I do not know how to write code.

Driver.get('https://video-download.online')
Url='https://www.youtube.com/watch?v=waQlR8W8aTA'
Driver.find_element_by_id("link").send_keys(Url)
Driver.find_element_by_id("submit").click()
time.sleep(5)
#[Click]lowermost(highest quality) radio button
#[Click]Proceed button

Answer

You are able to get frame locator value in HTML code which is specified in iframes tag. u can move up from where your locator value is existed in HTML code.

This function is suitable:

def frame_switch(css_selector):
  driver.switch_to.frame(driver.find_element_by_css_selector(css_selector))

If you are just trying to switch to the frame based on the name attribute, then you can use this:

def frame_switch(name):
  driver.switch_to.frame(driver.find_element_by_name(name))
Comments