Home > OS >  Selenium chrome driver unable to locate input element
Selenium chrome driver unable to locate input element

Time:02-12

Getting error when trying to locate the input element. Tried locating by xpath and className.

HTML of the Input Element:

<input data-v-9182d0dc="" type="text" id="filterElement" data-cy="v-search-input" autocomplete="off" placeholder="Type a name or a number" >

Xpath for this element:

//*[@id="filterElement"]

Full Xpath for this element: /html/body/div[2]/div[5]/div/div[2]/div/div[1]/div/div/div[2]/input

Statement to find the element

temp=driver.find_element_by_xpath('/html/body/div[2]/div[5]/div/div[2]/div/div[1]/div/div/div[2]/input')

Getting below error message:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[2]/div[5]/div/div[2]/div/div[1]/div/div/div[2]/input"}

enter image description here

Update: The element seems to be inside an iframe. Not sure how this comes into play when selecting an element

CodePudding user response:

To locate the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#filterElement[data-cy='v-search-input']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='filterElement' and @data-cy='v-search-input']")))
    
  • Note : You have to add the following imports :

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

References

You can find a couple of relevant discussions on NoSuchElementException in:

CodePudding user response:

I had to switch the iframe. The input element was located inside another iframe.

  • Related