0

I'm running into TimeoutException even after adding a wait time for WebDriver. I'm searching up SKUs one by one using data from a Pandas dataframe generated from an Excel spreadsheet.

My code never reaches the line where it sends the keys.

search_bar = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "(//div[contains(@class='searchbox-inner-searchtext')])")))
search_bar.send_keys(sku)
search_bar.send_keys(Keys.RETURN)

try:
    cross_click = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "(//*[@class='MuiSvgIcon-root'])[2]")))
    cross_click.click()
except Exception as e:
    print(e)
    print('No Product Found.')
    pass
1
  • The TimeoutException is BECAUSE of the WebDriverWait. It's timing out because it can't find the element you are looking for or it's not reached the state you are expecting... present, visible, clickable, etc. The most likely cause is that the locator is not correct or your element is in an IFRAME. Have you tested your locator in the browser using $$() or $x() to ensure that it's correct? Have you looked to see if your element is in an IFRAME? Commented May 5, 2021 at 20:09

2 Answers 2

1

I was able to find it using the FULL XPATH inspect option as well as your provided class name. I am sure there are other ways; I typically go with whatever is easiest unless being asked to test access a very specific way.

search_bar = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "/html/body/header/div[2]/div[1]/div/div[2]/div[2]/input")))
search_bar = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "searchbox-inner-searchtext")))
Sign up to request clarification or add additional context in comments.

Comments

1

contains() has a different syntax, the value has to be separated from the attribute by a comma.

The correct syntax is //div[contains(@class, 'searchbox-inner-searchtext')] for XPATH, or shorter div[class*='searchbox-inner-searchtext'] with CSS Selector.

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.