I am trying to switch to an iframe in selenium (Python). Though, no matter what I try, I keep getting an error.
iframes = driver.find_elements_by_tag_name('iframe')
print(len(iframes))
for iframe in iframes:
if 'ontouchmove' in iframe:
print(iframe)
driver.switch_to.frame(iframe)
This produces the error -
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'ELEMENT'
I have also tried this -
iframes = driver.find_elements_by_tag_name('iframe')
print(len(iframes))
counter = 0
for iframe in iframes:
if 'ontouchmove' in iframe:
print(iframe)
driver.switch_to.frame(counter)
counter += 1
this produces the error -
selenium.common.exceptions.JavascriptException: Message: javascript error: frame.setAttribute is not a function
I am not really sure what else I can do here, kind of lost.. any help would be appreciated.
Edit:
iframes = driver.find_elements_by_tag_name('iframe')
print(len(iframes))
driver.switch_to.frame(iframes[0])
This produces error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'ELEMENT'
This
if 'ontouchmove' in iframewill not work sinceiframehere is a web element, it is not a string but a web element object. So checking for text string in a web element is an invalid action.This
driver.switch_to.frame(counter)will not work as well sincedriver.switch_to.frame()intended to accept a web element as a parameter, not anintprimitive number.I'm not sure about the correct code that will work for you since I can't see the web page you are working on, I can only guess the following:
You can switch to those iframes and once you are inside them you can validate presence of element containing the desired text there. Something like this: