1

Here is the exception that I am getting:

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/

Here is the python code that I am running:

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")

Here is the link to the web page. I am trying to automate form filling in that website http://www.kseb.in/index.php?option=com_wrapper&view=wrapper&Itemid=813&lang=en

4 Answers4

1

This error message...

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

...implies that the ChromeDriver was unable to locate the desired <iframe> element.


Seems you were pretty close. The <iframe> have the src attribute set as http://103.251.43.139/~ksebuser/orumabills/upload/billview/. So mentioning the src attribute would have solved your issue.

However, as the the desired element is within an <iframe> so to send a character sequence within the element you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use either of the following Locator Strategies:

    • Using XPATH with src attribute:

      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")
      
    • Using CSS_SELECTOR with src attribute:

      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")
      
  • Browser Snapshot:

Consumer


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try using the name or id attribute to switch. May be try driver.switch_to_frame("iframe") or driver.switch_to_frame("blockrandom")

demouser123
  • 4,108
  • 9
  • 50
  • 82
0

The frame is not URL.

You can right click on the page to check if there has frame. It will show "View Frame Source". enter image description here

And find the id/name/index of frame.

enter image description here

driver.switch_to_frame("blockrandom") # frame id

Reference: https://www.techbeamers.com/switch-between-iframes-selenium-python/

Yun
  • 1,032
  • 7
  • 20
0

You are trying to switch by the src attribute, however switch_to_frame receive idor name attributes or WebElement as parameter. You should also replace the sleep() with WebDriverWait

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec

wait = WebDriverWait(driver, 10)
wait.until(ec.frame_to_be_available_and_switch_to_it('blockrandom'))
Guy
  • 46,488
  • 10
  • 44
  • 88