excel - 尝试从下拉框中选择项目
问题描述
尝试使用变量从下拉列表中选择项目。我可以单击下拉列表,我可以单击带有显式文本但不使用变量的项目。
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>
解决方案
您错过了字符串引号。请尝试以下选项。
Obj.FindElementByXPath("//option[@label='" & SomeStringVariable & "']").Click
推荐阅读
- c++ - C ++将stringstream转换为ifstream?
- email - 如果在 github 的特定路径中有新的提交,是否有通知用户
- c# - 无法建立到基于 SOAP 的服务的连接
- docker - 从 ipaddress 获取服务名称
- testing - Browserstack & Testcafe:无需语言环境测试即可使用
- sql - 输出查询结果
- python - 机器学习分类器使用过去的预测作为特征
- angular - 如何使用 Angular 9、Node JS、Express 和 MySQL 使用 select 将数据发布到后端
- python - 使用注释获取百分比给我结果而不用逗号 7/2 = 3 而不是 3.5
- automated-tests - 我们可以在不使用元素定位器的情况下自动化 Web 应用程序/移动应用程序吗