0

Im new on this coding stuff and im trying to access this search box from this website but i keep getting errors. When i try the same stuff on other websites it work but for some reason i cant do it here. https://shop.cummins.com/

This is the website:

This is the website

This is my code:

driver = webdriver.Chrome(Browserpath)
website = "https://shop.cummins.com/"
driver.maximize_window()
driver.get(website)

CumminsSearch =driver.find_element_by_xpath("/html/body/div[3]/div[2]/div/div[1]/div/div/c-dbu_home-page-header/div/header/div/div/div[4]/c-dbu_custom-search/div/form/lightning-input[2]/div/input")

time.sleep(10)

CumminsSearch.send_keys("test")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0
(//input[@placeholder='Search'])[1]

Use this xpath to get a unique identifier. Also use webdriver waits to allow the element to interactable.

CumminsSearch = wait.until(EC.element_to_be_clickable((By.XPATH,"(//input[@placeholder='Search'])[1]")))
CumminsSearch.send_keys("test")

Imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
0

To send a character sequence to the Search field you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "lightning-input[class*='dWindow'] input.slds-input[placeholder='Search']"))).send_keys("Wilbert Balbuena")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//lightning-input[contains(@class, 'dWindow')]//input[@class='slds-input' and @placeholder='Search']"))).send_keys("Wilbert Balbuena")
    
  • 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
    
  • Browser Snapshot:

shop_cummins

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