【问题标题】:Trying to fill text in input box with dynamic drop down尝试使用动态下拉菜单在输入框中填充文本
【发布时间】:2019-11-26 16:01:01
【问题描述】:

我需要一些帮助。在 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">

【问题讨论】:

  • 缺少&lt;&gt; 的HTML 看起来格式不正确。你可以交叉检查一次吗?
  • 抱歉,刚刚编辑了 HTML,谢谢!

标签: excel vba selenium xpath css-selectors


【解决方案1】:

要在所需元素中发送字符序列,您可以使用以下任一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")
    

参考

您可以在以下位置找到一些相关讨论:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 2023-04-05
    • 2020-12-19
    • 2018-09-19
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多