这是我得到的例外:
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")
浏览器快照:
参考
您可以在以下位置找到一些相关的讨论:
Ways to deal with #document under iframe