excel - 尝试使用动态下拉菜单在输入框中填充文本

标签 excel vba selenium xpath css-selectors

我需要一些帮助。在 Excel (2013) VBE 中使用 Selenium Basic ChromeDriver (v 75.0.3770.140) 的 Chrome (v 75.0.3770.100)。如果客户 id# 存在,则有一个输入框会生成一个动态列表。我希望填写客户 ID#,然后从动态下拉列表中选择。但第一步,我正在努力将我的文本输入到框中。我可以点击框

obj.FindElementById("selectcustTxt").Click

但是当我尝试用以下内容填写该框时:
obj.FindElementById("selectcustTxt").Value = "1111"

我收到一个错误运行时错误“424”:需要对象

我使用 .Value 和 .Text 尝试了以下 FindElementByXPath 但得到相同的运行时错误“424”:需要对象
obj.FindElementByXPath("//input[@class='form-control cust-autosuggest ng-pristine ng-valid ng-touched'][@id='selectcustTxt']").Value = "1111"

这是HTML:
<div class="form-group search-field"><input id="selectcustTxt" type="text" class="form-control cust-autosuggest ng-valid ng-touched ng-dirty ng-valid-parse" autocomplete="off" plshholder="Enter Cust name" autocomplepte="off" ng-model="cust" suggest-type="custService" sh-autosuggest="custAddresses" data-validation="required">

最佳答案

要在所需元素中发送字符序列,您可以使用以下任一 Locator Strategies :

  • 使用 FindElementByCss :
    obj.FindElementByCss("input.form-control.cust-autosuggest.ng-valid.ng-touched.ng-dirty.ng-valid-parse#selectcustTxt").SendKeys ("1111")
    
  • 使用 FindElementByXPath :
    obj.FindElementByXPath("//input[@class='form-control cust-autosuggest ng-valid ng-touched ng-dirty ng-valid-parse' and @id='selectcustTxt']").SendKeys ("1111")
    


  • 引用

    您可以在以下位置找到一些相关的讨论:
  • How to send text to some HTML elements?
  • Need help to fill number into Chrome input box with Selenium
  • 关于excel - 尝试使用动态下拉菜单在输入框中填充文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57082285/

    相关文章:

    excel - 为 SUMIF 函数选择命名范围的特定列

    vba - 按特定顺序将多个页面导出为 PDF

    vba - Excel 数组过滤器

    vba - 在 Excel VBA 中访问命名单元格的值(内容)

    html - 像 aria-label 这样的 ARIA 属性应该可以在 HTML5 中翻译吗?

    python - 如何使用Python截取Selenium中指定的WebElement

    excel - VBA检查工作表是否存在 - 需要对象错误

    java - 如何从excel文件中获取数据?

    vba - Excel 内的 Eval 评估

    selenium - TestNG 报告器 org.testng.reporters.JUnitReportReporter@7a79be86 失败 java.util.ConcurrentModificationException