【问题标题】:Trying to select item from dropdown box尝试从下拉框中选择项目
【发布时间】:2020-01-09 05:31:06
【问题描述】:

尝试使用变量从下拉列表中选择一个项目。 我可以点击下拉列表,我可以点击带有显式文本但不使用变量的项目。

Chrome (v 75.0.3770.142) 在 Excel (2013) VBA 中使用 Selenium Basic ChromeDriver (v 75.0.3770.140)。

如果我使用显式,它会起作用:

Obj.FindElementByXPath("//option[@label='Z01 - Customer Request - Paid']").Click

但如果使用字符串变量则不起作用:

Obj.FindElementByXPath("//option[@label=SomeStringVariable]").Click

这是 HTML:

<select id="tickboxreason" name="boxreason" class="emergency-reasons form-control ng-touched ng-dirty ng-valid-parse ng-valid ng-valid-required" ng-model="currentCartConfig.boxreason" ng-options="reason.displayValue for reason in reasonList.emergencyOrderReasons | orderBy:'code' track by reason.code" ng-change="updateRDD()" ng-required="currentCartConfig.emergencyFlag" required="required">
<option value="">Select Reason</option>
<option value="Z01" label="Z01 - Customer Request - Paid">Z01 - Customer Request - Paid</option>
</select>

【问题讨论】:

    标签: excel vba selenium web-scraping selenium-chromedriver


    【解决方案1】:

    你错过了字符串引号。试试下面的选项。

    Obj.FindElementByXPath("//option[@label='" & SomeStringVariable & "']").Click
    

    【讨论】:

      【解决方案2】:

      我会使用更快的 css 属性 = 值选择器

      obj.FindElementByCss("[label='" & variable & "']").click
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-13
        • 1970-01-01
        • 2020-01-11
        • 2019-01-24
        相关资源
        最近更新 更多