0
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import TimeoutException


driver = webdriver.Chrome()
driver.get('http://www.techfetch.com/JS/dashboard.aspx?page=fetchjobs')
time.sleep(5)
element = driver.find_element_by_xpath('//*[@id="txtKeyword"]')
element.send_keys("Java")

Error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="txtKeyword"]"}
  (Session info: chrome=62.0.3202.94)
  (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)

enter image description here

The Screen shot displays that the xpath is correct and available

viam0Zah
  • 25,949
  • 8
  • 77
  • 100
Raghav SK
  • 3
  • 1
  • 3
  • 4
    Possible duplicate of [selecting an iframe using python selenium](https://stackoverflow.com/questions/7534622/selecting-an-iframe-using-python-selenium). Have a look at the top voted answer, not the accepted one. – Guy Dec 12 '17 at 05:23

2 Answers2

2

Because the input field you are trying to fill in is within iframe. First switch it and then try to do what you did earlier:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://www.techfetch.com/JS/dashboard.aspx?page=fetchjobs')
time.sleep(5)
driver.switch_to_frame(driver.find_element_by_id("contentframe"))  ##switch it
driver.find_element_by_xpath('//*[@id="txtKeyword"]').send_keys("Java") 
SIM
  • 21,997
  • 5
  • 37
  • 109
0

To send a Character Sequence to the Keywords Box, first we need to wait for the frame to be available to switch to it then locate the Keywords Box to send the Character Sequence as follows :

driver.get('http://www.techfetch.com/JS/dashboard.aspx?page=fetchjobs')
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.XPATH,"//iframe[@id='contentframe']"))
element = driver.find_element_by_xpath("//input[@id='txtKeyword']")
element.send_keys("Java")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352