[英]Select radio button with dynamic Id, using CSS selector or Xpath
我在 Visual Studio 中使用 C# 到 select 多個是或否問題。 下面是 select“是”的第一個按鈕。 id
不是 static 所以不能使用它,我不確定哪個路徑(CSS 或 Xpath)對這條路線最有效。
<div class="row form-group">
<label class="form-label col-md-4 col-lg-3">Was everything satisfactory?</label>
<div class="col-md-7 col-lg-8"><fieldset class="form-group form-radio-group" id="__BVID__385">
<div tabindex="-1" role="group"><div role="radiogroup" tabindex="-1" class="" id="__BVID__386">
<div class="custom-control custom-control-inline custom-radio">
<input type="radio" autocomplete="off" class="custom-control-input" value="true" id="__BVID__387" name="__BVID__386">
<label class="custom-control-label" for="__BVID__387">Yes</label>
</div>
</div>
</div>
當您有動態 CSS Ids、名稱時,最好使用 Xpath。
根據您的要求(“選擇多個是或否問題”),您應該有一個關系 b/w 問題和選項。
您可以在兩個元素之間建立 Xpath 關系,如下面的示例所示。
//label[contains(.,'Was everything satisfactory?')]/following-sibling::div/fieldset/div/div/div/label[.='Yes' or .='No']
或者
//label[.='Yes' or .='No']/ancestor::div/parent::body/label[contains(.,'Was everything satisfactory')]
根據您的要求更新這些 Xpath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.