1

I have a problem with finding a WebElement in Selenium. I tried to fill the input field, this is the html:

<div class="container">
            <div class="tp-fl" id="btnSearchStockAutoComplete">
                <span class="tp-icon tp-search tp-co-3 "></span>
            </div>
            <angucomplete placeholder="search" searchfields="Not Found" pause="400" set-focus="tpFocus" selectedobject="tpSelected" titlefield="label" inputclass="form-control form-control-small" matchclass="highlight" api="tpApi" disable="disableSearchBox" stockdetails="stockdetails" class="ng-isolate-scope">
                <div class="tp-re angucomplete-holder tp-width">
                    <div id="fulltextContainer" style="display: none" class="symbol-info tp-etc">
                    </div>
                    <input id="txt_search" class="search-box tp-co-1 tp-pa-rl-5 tp-re tp-bo-bo" type="text" placeholder="Search" onmouseup="this.select();" autocomplete="off">
                    <div id="auto-list-container" class="auto-list-container tp-bg-2 tp-co-1 tp-bo-4 tp-bo tp-width angucomplete-dropdown" style="min-width: 250px; display: none">
                        <div style="display: none" id="loading" class="tp-h-35 tp-pa-rl-10 angucomplete-searching">Searching ...</div>
                        <div style="display: none" id="norecord" class="tp-35 tp-pa-rl-10 angucomplete-searching">Not Found </div>
                        <div id="list_dropdown">
                        </div>
                    </div>
                </div>
            </angucomplete>
        </div>

this is my code in python:

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

    browser=webdriver.Chrome('path')
    inputTxt=browser.find_element_by_xpath('//*[@id="txt_search"]')
    inputTxt.send_keys('stock')

but when I run this program, it gives me an error and throws an exception, "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable", I was wondering if there is any possible solution to this problem.

10
  • Do you need to interact with the page to trigger the search text field? The error is suggesting the element exists but is not "interactable". Commented Jun 28, 2019 at 15:00
  • I want to fill the input element as I mentioned, I used send_keys() method, but it throws this exception. On the webpage itself, input element is interactable and I can write any text in it. Commented Jun 28, 2019 at 15:15
  • Is there more then one element with that id? There might be more than one where the first is not the one you want. Commented Jun 28, 2019 at 16:07
  • try inputTxt.location_once_scrolled_into_view which will scrolled the element into view. Then try send_keys. Commented Jun 28, 2019 at 17:24
  • @JeffC thanks for your help, I checked the page source and I found three other elements with exact same id, but in different divs with different ids and classes. Now I should try to focus on one of them, but the problem is how I am able to define the true css-selector for it. I used inputTxt=browser.find_element_by_css_selector('app-content#txt_search') (the input field I want with id='txt_search' is inside the app-content tag), but it throws NoSuchElementException, I'm confused what the right style is to reach this element? Commented Jun 28, 2019 at 19:27

1 Answer 1

1

When you write the CSS selector app-content#txt_search, that means the HTML is something like <app-content id='txt_search'>...</app-content>. Joined together with no space between means they are all part of the same element. What you want is either app-content > #txt_search (> indicates child) or app-content #txt_search ( indicates descendant). From the HTML posted in your question, I'm assuming you want space because I don't see the parent <app-content> tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.