Jquery 当指定文本在页面上时用户脚本点击单选按钮

Jquery userscript clicking radio button when specified text is on the page

我正在尝试创建一个用户脚本,它将在 div 中搜索特定的文本字符串,如果可用,请单击该特定 div 中的特定单选按钮。每个页面通常有多个 div,每个页面都需要 div 最终处理。我已经尝试过使用 next() 和 nextAll() 的各种脚本,但我什至还没有接近它的工作。任何帮助将不胜感激。以下是如何对预期页面进行编码的示例:

<div class="block">
   <div>
      <div class="place">Text to be searched
      </div>
      <div class="place">
         <div id="question">
             <input value="yes">
             <input value="no">
         </div>
      </div>
   </div>
</div>

多次,最多 3 次。我是 javascript/jquery 的新手,任何人都可以为我指明方向以实现类似的功能吗?谢谢!

编辑: 多亏了一条非常有用的评论,我设法让它按照我需要的方式工作:

var arr = ['Keyword1', 'Keyword2', 'Keyword3'];
var i=0;
for (; i<arr.length; i++) {
$("div div.place.bg-dark:contains('"+arr[i]+"')").each(function() {
     $(this).nextAll().find('input[type=radio][value=2]').click();
    $(this).parent().parent().css("cssText", "border: 15px solid red !important;");
        });
}

使用.filter()过滤掉文本div或问题div然后使用.next('div.place')找到并标记选中所需的radio按钮.

查看下面的演示

var textToSearch = 'Text to be searched';
var valueToCheck='yes';

$(document).ready(function() {
  
  $(".block div.place").filter(function() {
    return $.trim($(this).text()) == textToSearch;
  }).next('div.place').find('input[type="radio"][value="'+valueToCheck+'"]').prop('checked', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="block">
  <div>
    <div class="place">Text to be searched</div>
    <div class="place">
      <div id="question">
        <input type="radio" value="yes">
        <input type="radio" value="no">
      </div>
    </div>
  </div>
  <div>
    <div class="place">Text to be searched
    </div>
    <div class="place">
      <div id="question">
        <input type="radio" value="yes">
        <input type="radio" value="no">
      </div>
    </div>
  </div>
</div>