首页 > 解决方案 > Selenium 查找选择节点的 xpath

问题描述

我正在尝试为以下内容生成 xpath:

    <select data-bind="options: PrinterLabelTypes, optionsValue: 'value', optionsText: 
    'value', value: NewPrinterLabelTypeText, optionsCaption: GetText('SelectLabelType')">. 
     <option value="">Choose Printer Label Type...</option><option 
    value="Batch">Batch</option><option value="Despatch">Despatch</option>
    </select>

我尝试了以下方法:

    //select[@data-bind='value: NewPrinterLabelTypeText']

但我没有得到任何回报。我错过了什么吗。有没有办法使用上面的格式来做到这一点?

标签: c#htmlxpath

解决方案


contains当您的定位器使用部分属性值时,您必须使用。

//select[contains(@data-bind,'value: NewPrinterLabelTypeText')] 

推荐阅读