简体   繁体   English

尝试从下拉框中选择项目

[英]Trying to select item from dropdown box

Trying to select an item from a drop down list using a variable.尝试使用变量从下拉列表中选择项目。 I'm able to click the drop down list, I'm able to click on the item with explicit text but not using a variable.我可以单击下拉列表,我可以单击带有显式文本但不使用变量的项目。

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

it works if i use explicit:如果我使用显式,它会起作用:

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

but doesn't work if using a string variable:但如果使用字符串变量则不起作用:

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

Here's the HTML:这是 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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM