Selenium - Difficulty finding input element on page (Python)
<p>I am having trouble finding a search bar on a webpage that I am trying to automate. I have tried a couple approaches but being rather new to selenium, I am not sure what more advanced locating options there are.</p>

<p>Breakdown::
The following is an section of code with the search bar element (corresponding to input) being highlighted</p>

<p><a href="https://i.stack.imgur.com/Zsu6g.png" rel="nofollow">The xpath to the following highlighted section is below</a>:</p>

<pre><code>//*[@id='core-content-container']/div/div[2]/div/div[1]/nav/div/div[2]/form/ul/li[1]/input
</code></pre>

<p>When I try to find this element via find_element_by_xpath however, I get a <code>NoSuchElementException</code> (I have tried shorter xpaths but those provided the same error)</p>

<p>Below is the relevant code bit I am using to try to find this element:</p>

<pre><code>from selenium import webdriver

driver = webdriver.Firefox()

#DNSMgr
driver.get('https://barista.cac.washington.edu/dnsmgr/#/fqdn')

driver.find_element_by_xpath("//div[@id='core-content-container']/div/div[2]/div/div[1]/nav/div/div[2]/form/ul/li[1]/input")
</code></pre>

<p>Since the exact line that I am trying to get at looks like this:</p>

<pre><code>&lt;input type="text" class="form-control ng-pristine ng-untouched ng-valid" ng-model="query" placeholder="Full domain name"&gt;
</code></pre>

<p>I then thought that maybe I could get at the element by using</p>

<pre><code>driver.find_element_by_css_selector('input.form-control.ng-pristine.ng-untouched.ng-valid')
</code></pre>

<p>Since this is similar to the example on seleniums python tutorials in section 4.7 I thought that could do the job but that also doesn't work (I get another <code>NoSuchElementException</code>).</p>

<p>If you are getting <code>NoSuchElementException</code> as your provided exception, There could be following reasons :-</p>

<ul>
<li><p>May be when you are going to find element, it would not be present on the <code>DOM</code>, So you should implement <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow"><code>Explicit wait</code></a> using <code>WebDriverWait</code> to wait until element is present as below :-</p>

<pre><code>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

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div#core-content-container input.form-control[ng-model='query'][placeholder='Full domain name']")))
</code></pre></li>
<li><p>May be this element is inside any <code>frame</code> or <code>iframe</code>. If it is, you need to switch that <code>frame</code> or <code>iframe</code> before finding the element as below :-</p>

<pre><code> wait = WebDriverWait(driver, 10)

#Find frame or iframe and switch
wait.until(EC.frame_to_be_available_and_switch_to_it(("frame/iframe id or name")))

#Now find the element 
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "div#core-content-container input.form-control[ng-model='query'][placeholder='Full domain name']")))

#Once all your stuff done with this frame need to switch back to default
driver.switch_to_default_content()
</code></pre></li>
</ul>

python selenium