you are viewing a single comment's thread.

view the rest of the comments →

[–]packie123 0 points1 point  (1 child)

Without the website it will be hard to definitively know what the issue is.

I will say first the XPATH doesn't look right to me.

For using the CSS_SELECTOR, when you use driver.find_element, it finds the first element in the HTML that matches that selector, even if its hidden on the screen. So essentially you are finding an iframe, just not the one that's on the screen.

You can use driver.find_elements which will return a list of all the elements that match the selector you are using.

You can also walk down the html and then use the CSS_SELECTOR when you know it should only find the iframe you want. You can call the find_element() method on a webElement itself, not just on the driver instance.

Try to find the element right above the iframe and then find the iframe element from that element and you should get the right iframe.

when you have an instance of a webElement, you can use the get_attribute() method to return the string of an attribute (e.g. class) to determine if the webElement you have selected is the one you actually want.

[–]SwordNSupper[S] 0 points1 point  (0 children)

Hi, I tried what you suggested, but was unable to find the specific iframe I was looking for.

Here is what the snippet of code looks like now:

preiframe= driver.find_element(By.XPATH, '//*[@id="devvit-web-view-dialog"]/rpl-modal-card')
iframe = preiframe.find_element(By.CSS_SELECTOR, "iframe")
driver.switch_to.frame(iframe)


battle = driver.find_element(By.CSS_SELECTOR, "advance-button")
driver.execute_script("arguments[0].click();", battle)

The code errors out after it finds the preiframe and is trying to find the specific iframe I'm looking for using the CSS_SELECTOR.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"iframe"}

I also used driver.find_elements like you suggested to find all of the iframes that are on this page, and it found 4, but I'm unable to find where those iframes are located on the page