使用frame_to_be_available_and_switch_to_it 找到不到iframe 报错selenium.common.exceptions.TimeoutException:

在执行Python Selenium脚本时遇到了TimeoutException错误,具体发生在尝试使用`frame_to_be_available_and_switch_to_it`方法切换到iframe时。错误堆栈追踪显示问题可能源于WaitUtil.py文件中的frameToBeAvailableAndSwitchToIt函数。现在需要大神帮助分析并解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def waitFrameToBeAvailableAndSwitchToIt(locationType, locatorExprexxion, *args):
    # 检查frame 是否存在,存在则切换进frame控件中
    global waitUtil,driver
    try:
        waitUtil.frameToBeAvailableAndSwitchToIt(locationType, locatorExprexxion)
    except Exception as e:
        raise e
    def frameToBeAvailableAndSwitchToIt(self,locationType,locatorExpression,*arg):
        #检查frame是否存在 存在则切换进frame空间中
        try:
            self.wait.until(
                EC.frame_to_be_available_and_switch_to_it((
                    self.locationTypeDict[locationType.lower()],
                        locatorExpression)))
        except Exception as e:
            #抛出异常信息给上层调用者
            raise e

以下是报错 请大神指点!!!!

Traceback (most recent call last):
  File "G:\KeyWordFromeWork\testScripts\TestSendMailWithAttachment.py", line 296, in TestSendMailWithAttachment
    eval(expressionStr)
  File "<

========================================================================================================== test session starts =========================================================================================================== platform win32 -- Python 3.7.3, pytest-7.4.4, pluggy-1.2.0 -- d:\python\python.exe cachedir: .pytest_cache metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.22621-SP0', 'Packages': {'pytest': '7.4.4', 'pluggy': '1.2.0'}, 'Plugins': {'html': '3.2.0', 'metadata': '3.0.0', 'ordering': '0.6', 'rerunfailures': '13.0'}} rootdir: D:\pythonProject\ryTest configfile: pytest.ini testpaths: ./scripts plugins: html-3.2.0, metadata-3.0.0, ordering-0.6, rerunfailures-13.0 collected 2 items scripts/test_01.py::Test01::test_login DevTools listening on ws://127.0.0.1:61065/devtools/browser/19c757d3-cfd7-4475-9a59-c604539f9b1c [15068:2140:0620/153723.761:ERROR:net\socket\ssl_client_socket_impl.cc:892] handshake failed; returned -1, SSL error code 1, net_error -101 [15068:2140:0620/153723.856:ERROR:net\socket\ssl_client_socket_impl.cc:892] handshake failed; returned -1, SSL error code 1, net_error -101 PASSED scripts/test_01.py::Test01::test_home FAILED ================================================================================================================ FAILURES ================================================================================================================ ____________________________________________________________________________________________________________ Test01.test_home ____________________________________________________________________________________________________________ self = <scripts.test_01.Test01 object at 0x00000249B20B90B8> def test_home(self): self.Homeproxy.go_page() > self.AddProxy.go_add("买菜","50") scripts\test_01.py:20: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ page\mp\add_page.py:48: in go_add self.AddHandle.input_addname(addname) page\mp\add_page.py:35: in input_addname UtilsDriver.get_mp_driver().switch_to.frame(self.AddPage.find_iframe2()) page\mp\add_page.py:20: in find_iframe2 return self.get_element(self.iframe2) base\mp\base.py:11: in get_element element=wait.until(lambda x:x.find_element(*location)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <selenium.webdriver.support.wait.WebDriverWait (session="70fff24adb85ae9b274759a5b8bcdb58")>, method = <function BasePage.get_element.<locals>.<lambda> at 0x00000249B20B51E0>, message = '' def until(self, method, message: str = ""): """Calls the method provided with the driver as an argument until the \ return value does not evaluate to ``False``. :param method: callable(WebDriver) :param message: optional message for :exc:`TimeoutException` :returns: the result of the last call to `method` :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs """ screen = None stacktrace = None end_time = time.monotonic() + self._timeout while True: try: value = method(self._driver) if value: return value except self._ignored_exceptions as exc: screen = getattr(exc, "screen", None) stacktrace = getattr(exc, "stacktrace", None) time.sleep(self._poll) if time.monotonic() > end_time: break > raise TimeoutException(message, screen, stacktrace) E selenium.common.exceptions.TimeoutException: Message: E Stacktrace: E GetHandleVerifier [0x0x7ff704133905+25605] E (No symbol) [0x0x7ff704083a10] E Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff7043b6f1a+1962506] E (No symbol) [0x0x7ff703e986c4] E (No symbol) [0x0x7ff703e9898b] E (No symbol) [0x0x7ff703ed9af7] E (No symbol) [0x0x7ff703eb9e8f] E (No symbol) [0x0x7ff703e8ea5d] E (No symbol) [0x0x7ff703ed75df] E (No symbol) [0x0x7ff703eb9bb3] E (No symbol) [0x0x7ff703e8df56] E (No symbol) [0x0x7ff703e8d463] E (No symbol) [0x0x7ff703e8dd83] E (No symbol) [0x0x7ff703f8e10d] E (No symbol) [0x0x7ff703f9dce8] E Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff7042188d9+265161] E Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff7042201b1+296097] E (No symbol) [0x0x7ff7040921b1] E (No symbol) [0x0x7ff70408a654] E (No symbol) [0x0x7ff70408a7a3] E (No symbol) [0x0x7ff70407b976] E BaseThreadInitThunk [0x0x7ffb94f0259d+29] E RtlUserThreadStart [0x0x7ffb9580af78+40] C:\Users\YangYuQuan\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\wait.py:95: TimeoutException ======================================================================================================== short test summary info ========================================================================================================= FAILED scripts/test_01.py::Test01::test_home - selenium.common.exceptions.TimeoutException: Message: ====================================================================================================== 1 failed, 1 passed in 17.78s ======================================================================================================
最新发布
06-21
import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException # 启动浏览器 browser = webdriver.Edge() browser.set_page_load_timeout(60) # 设置页面加载超时时间为 60 秒 browser.get("https://sep.ucas.ac.cn/appStoreStudent") try: # 等待页面完全加载 WebDriverWait(browser, 30).until( lambda d: d.execute_script("return document.readyState") == "complete" ) # 显式等待用户名输入框加载 username_input = WebDriverWait(browser, 30).until( EC.presence_of_element_located((By.ID, "userName1")) ) username_input.send_keys('wanglihui24@mails.ucas.ac.cn') # 定位密码输入框 password_input = WebDriverWait(browser, 30).until( EC.presence_of_element_located((By.ID, 'pwd1')) ) password_input.send_keys('5544941Aa@') # 显式等待验证码输入框加载 captcha_input = WebDriverWait(browser, 30).until( EC.presence_of_element_located((By.ID, "certCode1")) ) print("请输入验证码,你有 30 秒时间...") time.sleep(30) # 留出时间手动输入验证码 # 提交表单 submit_button = WebDriverWait(browser, 30).until( EC.element_to_be_clickable((By.ID, 'submit')) ) submit_button.click() # 等待页面加载完成 WebDriverWait(browser, 30).until( lambda d: d.execute_script("return document.readyState") == "complete" ) # 找到文献下载模块的链接并点击 # 假设文献下载模块的链接有一个特定的 ID 或者可以通过其他方式定位 # 找到文献下载模块的链接并点击 try: # 通过 class 属性定位文献下载模块的链接 download_link = WebDriverWait(browser, 30).until( EC.element_to_be_clickable((By.CLASS_NAME, 'px-2 py-1 rounded')) ) download_link.click() except TimeoutException: print("通过 class 属性未找到文献下载模块链接,尝试使用其他定位方式...") try: # 通过 href 属性定位文献下载模块的链接 download_link = WebDriverWait(browser, 30).until( EC.element_to_be_clickable((By.XPATH, "https://sep.ucas.ac.cn/portal/site/377/1994']")) ) download_link.click() except TimeoutException: print("文献下载模块链接仍未找到,跳过该步骤...") # 等待文献下载模块页面加载完成 WebDriverWait(browser, 30).until( lambda d: d.execute_script("return document.readyState") == "complete" ) print("成功进入文献下载模块。") except TimeoutException: print("超时错误:页面加载或元素定位超时。") except Exception as e: print("未知错误:", e) finally: time.sleep(5) browser.quit()为什么进入系统后,不能自动进入文献下载模块
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值