硒无法通过xpath查找元素

萨沙扬克

我正在通过抓取特定网站来学习硒我正在尝试访问邮政编码输入字段,以尝试更改邮政编码。到目前为止,这是我的代码

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)
    

根据上面的代码,这部分每次都会失败

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)))

我不确定自己在做什么错。XPATH我所知,这是正确的。但是程序在这里失败。我也没有收到适当的异常消息。这是返回的异常

Message:

请帮帮我

编辑1:

这是我要定位的邮政编码输入框

在此处输入图片说明

阿伦迪普乔汉

您可以简单地做到这一点。将邮政编码更改为字符串。以及获得更简单的ID作为目标。

zipcode = '000001'
zipcode_input_path = "areaselect"
        
zipcode_input = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, zipcode_input_path)))
zipcode_input.send_keys(zipcode)

目标元素

<input qa="areaInput" typeahead-min-length="3" id="areaselect" ng-change="vm.emptyCheck()" autocomplete="off" name="area" type="text" placeholder="Enter your area / apartment / pincode" ng-model="vm.selectedlocation.query" uib-typeahead="address.label for address in vm.getAreasForCity($viewValue)" typeahead-loading="loadingLocations" typeahead-on-select="vm.onSelect($item)" typeahead-editable="false" typeahead-select-on-blur="true" typeahead-select-on-exact="true" required="" typeahead-no-results="noResultsArea" typeahead-focus-on-select="true" typeahead-wait-ms="200" style="width: 100%; height: 35px; color: rgb(51, 51, 51); padding: 4px 15px;" class="ng-pristine ng-valid-editable ng-empty ng-invalid ng-invalid-required ng-touched" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-47-9856">

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

硒:如何通过部分href查找元素?

来自分类Dev

无法使用硒读取xpath元素

来自分类Dev

XPath:通过纯文本查找HTML元素

来自分类Dev

通过XPath相对查找元素

来自分类Dev

硒-无法通过类名找到元素

来自分类Dev

硒:通过可见文本查找元素

来自分类Dev

硒无法通过ID选择元素

来自分类Dev

硒查找按钮元素

来自分类Dev

硒,Java。需要通过Xpath选择表内的祖先元素

来自分类Dev

具有XPath的Java硒查找元素

来自分类Dev

硒无法通过类名称查找元素

来自分类Dev

python中的硒通过相对xpath查找元素

来自分类Dev

无法使用XPath按索引查找元素

来自分类Dev

硒无法通过ID或xpath找到元素

来自分类Dev

通过LXML通过XPATH查找元素-Python

来自分类Dev

如何通过硒使用CSS选择器查找元素

来自分类Dev

硒无法通过类名称找到元素

来自分类Dev

Selenium:无法通过XPATH Python查找元素

来自分类Dev

无法使用硒读取xpath元素

来自分类Dev

硒-python-通过内部HTML查找元素

来自分类Dev

如何使用xpath通过父级查找元素?C#硒

来自分类Dev

无法使用硒从网站中查找元素

来自分类Dev

硒:通过可见文本查找元素

来自分类Dev

具有XPath的Java硒查找元素

来自分类Dev

使用硒无法通过 id 找到元素

来自分类Dev

硒在元素内查找元素

来自分类Dev

无法使用硒通过 ID 获取元素

来自分类Dev

无法使用 XPath 查找元素 - NoSuchElementException

来自分类Dev

在硒中查找元素