So, I was absolutely baffled as to how to do this in Selenium, and couldn\'t find the answer anywhere, so I\'m sharing my experience.
I was trying to select an ifram
you can use this simple code to look for the iframe using xpath
sample use set_iframe("/html/body/div[2]/table/")
def set_iframe(xpath):
print('set_iframe')
driver.switch_to.default_content()
seq = driver.find_elements_by_tag_name('iframe')
for x in range(0, len(seq)):
driver.switch_to.default_content()
print ("iframe-"+str(x))
try:
driver.switch_to.frame(int(x))
driver.find_element_by_xpath(xpath)
return str(x)
except:
continue