1

So I cannon't find The input Box

Html:

<div id="w0-find-product"><div class="search-bar" id="w0-find-product-search-bar"><div class="textbox flex-wrapper"><div class="input-wrapper"><input autofocus="" type="text" class="find-product" placeholder="Enter UPC, ISBN, ePID, part number, or product name" role="combobox" aria-owns="w0-find-product-search-bar-autocomplete" aria-expanded="false" aria-autocomplete="list" autocomplete="off" maxlength="100" value="" id="w0-find-product-search-bar-search-field" data-w-onkeydown="checkKey|w0-find-product-search-bar"><span class="clipped" role="status" aria-live="polite" aria-atomic="true" id="w0-find-product-search-bar-search-bar-suggestions-count"></span></div><button class="btn btn--primary btn--large" disabled="" type="button" id="w0-find-product-search-bar-search-button" data-w-onclick="beforeSearch|w0-find-product-search-bar">Get started</button></div></div></div>

Python Code Below:

SearchBar = browser.find_element_by_xpath('//*[@id="w0-find-product"]')

Error Below:

   Traceback (most recent call last):
  File "C:/Users/Nothing/.PyCharmCE2018.3/config/scratches/sd.py", line 23, in <module>
    SearchBar =browser.find_element_by_xpath('//*[@id="w0-find-product"]')
  File "C:\Users\Nothing\PycharmProjects\UploadBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\Nothing\PycharmProjects\UploadBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\Nothing\PycharmProjects\UploadBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Nothing\PycharmProjects\UploadBot\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="w0-find-product"]"}
  (Session info: chrome=72.0.3626.96)
  (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 6.1.7601 SP1 x86_64)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ali Al-Jabur
  • 77
  • 1
  • 9

3 Answers3

0

If you want to find the search bar itself, use browser.find_element_by_id('w0-find-product-search-bar-search-field').

AmagicalFishy
  • 1,249
  • 1
  • 12
  • 36
0

Please try this with xpath.Both should work.

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



element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//input[@id="w0-find-product-search-bar-search-field"]')))
element.send_keys("1234")

OR

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

element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//input[@class="find-product"]')))
element.send_keys("1234") 

OR

driver.execute_script(("document.getElementById('w0-find-product-search-bar-search-field').value='1234'"))
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Tried Both already And I did so again but it still hasn't worked. – Ali Al-Jabur Feb 12 '19 at 21:07
  • I'm using python and i don't know to change it would you mind doing for me thanks! – Ali Al-Jabur Feb 12 '19 at 21:26
  • You have to import following to do so. ```from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By``` – KunduK Feb 12 '19 at 21:28
  • Please post here if you get any error.so that i can trace here. – KunduK Feb 12 '19 at 21:30
  • Traceback (most recent call last): File "C:/Users/Public.WALLINET-11/.PyCharmCE2018.3/config/scratches/sd.py", line 27, in element = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, '//input[@id="w0-find-product-search-bar-search-field"]'))) File "C:\Users\Public.WALLINET-11\PycharmProjects\UploadBot\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: – Ali Al-Jabur Feb 12 '19 at 21:34
  • so it is giving time out exception not that path is not found. – KunduK Feb 12 '19 at 21:37
  • I got the answer probably.Try the last one.I have updated. – KunduK Feb 12 '19 at 21:38
  • Ya exactly it might be because i have a 4 sec time.sleep idk if that has a effect just letting you know – Ali Al-Jabur Feb 12 '19 at 21:39
  • Now I'm Getting this Error: – Ali Al-Jabur Feb 12 '19 at 21:42
  • weird.All 3 options working fine in my laptop.Just increase 10 seconds to 30 secs see any difference. – KunduK Feb 12 '19 at 21:47
0

First of all, as you are using chrome=72, as per ChromeDriver - WebDriver for Chrome you need to download and use either of the following binaries but not chromedriver=73:

Next, to locate the <input> element you can use either of the following solutions:

  • Using CSS_SELECTOR:

    SearchBar = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.find-product#w0-find-product-search-bar-search-field[placeholder^='Enter UPC']")))
    
  • Using XPATH:

    SearchBar = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='find-product' and @id='w0-find-product-search-bar-search-field'][starts-with(@placeholder, 'Enter UPC')]")))
    
  • 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
    

Note: You can find a relevant discussion in Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome

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