尝试使用动态下拉菜单在输入框中填充文本 [英] Trying to fill text in input box with dynamic drop down

查看:48
本文介绍了尝试使用动态下拉菜单在输入框中填充文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need some help. Chrome (v 75.0.3770.100) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE. There's an input box which generates a dynamic list if the customer id# exists. I wish to fill in the customer id# then select from the dynamic drop down. But first step, I'm struggling to input my text to the box. I'm able to click on the box with

obj.FindElementById("selectcustTxt").Click

但是当我尝试在框中填写:

but when I try to fill in the box with:

obj.FindElementById("selectcustTxt").Value = "1111"

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

I get an error Run-time error '424': Object required

我尝试了同时使用.Value和.Text的以下FindElementByXPath,但是得到了相同的运行时错误'424':所需对象

I tried the following FindElementByXPath with both .Value and .Text but get the same Run-time error '424': Object required

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

推荐答案

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

To send a character sequence within the desired element you can use either of the following 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")
    

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

    You can find a couple of relevant discussions in:

    这篇关于尝试使用动态下拉菜单在输入框中填充文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆