首页 > 解决方案 > 尝试从下拉框中选择项目

问题描述

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

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>

标签: excelvbaseleniumweb-scrapingselenium-chromedriver

解决方案


您错过了字符串引号。请尝试以下选项。

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

推荐阅读