error switching to iframe selenium python

2024/10/5 14:57:29

Currently I'm attempting to switch to iframe/fancybox, but i'm getting the following error:

line 237, in check_response raise exception_class
(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: 
Message: unknown error: missing 'ELEMENT'

This is how I'm locating the iframe:

_iframe_ = {"by": By.XPATH, "value": "//iframe[@class='fancybox-iframe' and starts-with(@id,'fancybox-frame') and contains(@src,'/reminder/add/relation/')]"}def __init__(self, driver):super(BasePage, self).__init__()self.driver = driveself.driver.switch_to.frame(self._iframe_)

iframe name is:

fancybox-frame1518441842751" 

html:

  <iframe id="fancybox-frame1518443041369" name="fancybox-frame1518443041369" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" scrolling="auto" src="/reminder/add/relation/58048" kwframeid="1"></iframe>
Answer

The id and name attributes looks dynamic (the number doesn't match in the code and html). You can try to locate by partial id/name

_iframe_ = {"by": By.CSS_SELECTOR, "value": "[id*='fancybox-frame']"}
# "[name*='fancybox-frame']"

As a side note, frame() can receive id/name as parameter

self.driver.switch_to.frame('fancybox-frame1518441842751')

Would have worked (except for the dynamic issue of course).

https://en.xdnf.cn/q/120259.html

Related Q&A

SQL Date Variables in Python

I am writing a query inside a Python script.The query is as follows:cur = conn.cursor() query1 = """select max(date_time) from tablename""" cur.execute(queryy1) conn.commi…

Truble to create a matrix for sudoku in python

I have to make a sudoku template, so I need to get random numbers into the matrix, but they can not be repeated in the rows or columns, but I can not do it. For this I can not use numpy. In this case I…

Password validation in python with regex without duplicate chars

The parameter is a string. Check whether it forms a secure password.A password is safe ifthere is at least a lowercase letter in it, and there is at least one capital letter in it, and there is at leas…

Processing non-english text

I have a python file that reads a file given by the user, processes it, and ask questions in flash card format. The program works fine with an english txt file but I encounter errors when trying to pro…

Downloading all zip files from url

I need to download all the zip files from the url: https://www.ercot.com

sql to query set

I have 2 tables:puzz_meeting_candidats :- id, canceled, candidat_id, meeting_id puzz_meeting :- id, ClientI have a query follow: SELECT U1.`candidat_id` AS Col1 FROM `puzz_meeting_candidats` U1 INN…

Google App Engine, best practice to schedule code execution [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

delete rows by date and add file name column for multiple csv

I have multiple "," delimited csv files with recorded water pipe pressure sensor data, already sorted by date older-newer. For all original files, the first column always contains dates forma…

X = Y = Lists vs Numbers [duplicate]

This question already has answers here:Immutable vs Mutable types(20 answers)How do I clone a list so that it doesnt change unexpectedly after assignment?(24 answers)Closed 4 years ago.In python : I h…

Python data text file grades program

Looking for help with my program. There is a text file with 5 first and last names and a number grade corresponding to each person. The task is to create a user name and change the number grade to a le…