I am learning selenium by trying to scrape a particular website. I am trying to access the zipcode input field to try and change the zipcode. This is my code so far
try:
selector = '.btn.hvr-fade'
button = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector)))
button.click()
selector = ".btn.btn-default.form-control.ui-select-toggle"
city_dropdown = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector)))
city_dropdown.click()
city = 'Mumbai'
city = city.title()
city_path = "//a[@class='ui-select-choices-row-inner']//span[contains(text(), '%s')]" % city
city_element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, city_path)))
city_element.click()
time.sleep(1)
zipcode = 000001
zipcode_input_path = "//form[@class='ng-valid-editable ng-invalid ng-invalid-required ng-dirty']//div[@class='form-group area-autocomplete area-select ng-scope']//input[@name='ng-
pristine ng-untouched ng-valid-editable ng-empty ng-invalid ng-invalid-required']"
zipcode_input = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, zipcode_input_path)))
zipcode_input.send_keys(zipcode)
except Exception as e:
print('scraping could not be completed')
print(e)
From the above code this part fails everytime
zipcode_input_path = "//form[@class='ng-valid-editable ng-invalid ng-invalid-required ng-dirty']//div[@class='form-group area-autocomplete area-select ng-scope']//input[@name='ng-pristine ng-untouched ng-valid-editable ng-empty ng-invalid ng-invalid-required']"
zipcode_input = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, zipcode_input_path)))
I am not sure what I am doing wrong. The XPATH to the best of my knowledge is correct. But the program fails here. I am also not getting a proper exception message. This is the exception that is returned
Message:
Please help me out
EDIT1:
This is the zipcode input box I am trying to target

//in the middle instead of/?//should search for the required element in the given path right?/, except for the first leading//? And yes they do have a difference,//searches from the root while/searches from the previous given element