我需要触摸兄弟元素“ ng-form”的子元素:“ input”,该元素是在触摸前一个兄弟姐妹的子元素“ input”时动态创建的
我想根据我所需的String数组数据选择并触摸同级的输入元素。因为兄弟姐妹被添加为先前的兄弟姐妹孩子:触摸了输入
当前这是我的html表单
KeyError Traceback (most recent call last)
<ipython-input-33-04550f0541ec> in <module>()
1 resulting_tag = soup.select_one('Committed')
2 type(resulting_tag)
----> 3 resulting_tag['Committed']
/usr/local/lib/python3.6/dist-packages/bs4/element.py in __getitem__(self, key)
1069 """tag[key] returns the value of the 'key' attribute for the tag,
1070 and throws an exception if it's not there."""
-> 1071 return self.attrs[key]
1072
1073 def __iter__(self):
KeyError: 'Committed'
这是我正在尝试的事情
<ng-form name="streamValueForm>
<input name="name" class="ng-touched ng-valid"/>
</ng-form>
<ng-form name="streamValueForm>
<input name="name" class="ng-untouched ng-invalid"/>
</ng-form>
当我触摸输入元素(即ng-form的子元素)时,兄弟姐妹不断添加ng-form
答案 0 :(得分:0)
如果要选择ng-untouched ng-invalid
的输入字段:
您可以使用以下CSS选择器:
ng-form[value='streamValueForm'] input[class*='ng-invalid']
Xpath将是:
//ng-form[@value='streamValueForm']/input[contains(@class,'ng-invalid')]