gpt4 book ai didi

python - Selenium 中的 NoSuchFrameException(frame_reference)

转载 作者:太空宇宙 更新时间:2023-11-03 19:45:09 24 4
gpt4 key购买 nike

这是我遇到的异常:

Traceback (most recent call last):
File "/home/navendu/lead-generator/python_scripts/tempCodeRunnerFile.py", line 12, in <module>
driver.switch_to_frame("http://103.251.43.139/~ksebuser/orumabills/upload/billview/")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 789, in switch_to_frame
self._switch_to.frame(frame_reference)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/switch_to.py", line 87, in frame
raise NoSuchFrameException(frame_reference)
selenium.common.exceptions.NoSuchFrameException: Message: http://103.251.43.139/~ksebuser/orumabills/upload/billview/

这是我正在运行的 python 代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("http://www.kseb.in/index.php?option=com_wrapper&view=wrapper&Itemid=813&lang=en")
driver.maximize_window()
driver.implicitly_wait(7)
driver.switch_to_frame("http://103.251.43.139/~ksebuser/orumabills/upload/billview/")

ele = driver.find_element_by_id('t_consumer-no_5')
ele.send_keys("some text")

这是网页的链接。我正在尝试在该网站上自动填写表格 http://www.kseb.in/index.php?option=com_wrapper&view=wrapper&Itemid=813&lang=en

最佳答案

此错误消息...

selenium.common.exceptions.NoSuchFrameException: Message: http://103.251.43.139/~ksebuser/orumabills/upload/billview/

...暗示 ChromeDriver 无法找到所需的 <iframe>元素。

<小时/>

看来你们已经很接近了。 <iframe>src 属性设置为 http://103.251.43.139/~ksebuser/orumabills/upload/billview/ 。因此,提及 src 属性就可以解决您的问题。

但是,由于所需的元素位于 <iframe> 内因此,要在元素内发送字符序列,您必须:

  • 引发WebDriverWait以使所需的框架可用并切换到它
  • 引发WebDriverWait以使所需的元素可点击
  • 您可以使用以下任一 Locator Strategies :

    • 使用 XPATH带有 src 属性:

      driver.get("http://www.kseb.in/index.php?option=com_wrapper&view=wrapper&Itemid=813&lang=en")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src, 'ksebuser/orumabills/upload/billview/')]")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='userInputText']"))).send_keys("Navendu_Pottekkat")
    • 使用 CSS_SELECTOR带有 src 属性:

      driver.get("http://www.kseb.in/index.php?option=com_wrapper&view=wrapper&Itemid=813&lang=en")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src$='ksebuser/orumabills/upload/billview/']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.userInputText"))).send_keys("Navendu_Pottekkat")
  • 浏览器快照:

Consumer

<小时/>

引用

您可以在以下位置找到一些相关讨论:

关于python - Selenium 中的 NoSuchFrameException(frame_reference),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60182107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com